          self.assertIsInstance(
              list(SimpleItem.objects.annotate(Count('feature')).only('name')),
              list)
  
      def test_ticket_11936(self):
          app_config = apps.get_app_config("defer_regress")
          # Regression for #11936 - get_models should not return deferred models
          # by default. Run a couple of defer queries so that app registry must
          # contain some deferred classes. It might contain a lot more classes
          # depending on the order the tests are ran.
          list(Item.objects.defer("name"))
          list(Child.objects.defer("value"))
          klasses = {model.__name__ for model in app_config.get_models()}
          self.assertIn("Child", klasses)
          self.assertIn("Item", klasses)
          self.assertNotIn("Child_Deferred_value", klasses)
          self.assertNotIn("Item_Deferred_name", klasses)
          self.assertFalse(any(k._deferred for k in app_config.get_models()))
  
          klasses_with_deferred = {model.__name__ for model in app_config.get_models(include_deferred=True)}
          self.assertIn("Child", klasses_with_deferred)
          self.assertIn("Item", klasses_with_deferred)
          self.assertIn("Child_Deferred_value", klasses_with_deferred)
          self.assertIn("Item_Deferred_name", klasses_with_deferred)
          self.assertTrue(any(k._deferred for k in app_config.get_models(include_deferred=True)))
  
      @override_settings(SESSION_SERIALIZER='django.contrib.sessions.serializers.PickleSerializer')
      def test_ticket_12163(self):
          # Test for #12163 - Pickling error saving session with unsaved model
          # instances.
          SESSION_KEY = '2b1189a188b44ad18c35e1baac6ceead'
 
</s> remove # This function is needed because data descriptors must be defined on a class
# object, not an instance, to have any effect.

def deferred_class_factory(model, attrs):
    """
    Returns a class object that is a copy of "model" with the specified "attrs"
    being replaced with DeferredAttribute objects. The "pk_value" ties the
    deferred attributes to a particular instance of the model.
    """
    if not attrs:
        return model
    opts = model._meta
    # Never create deferred models based on deferred model
    if model._deferred:
        # Deferred models are proxies for the non-deferred model. We never
        # create chains of defers => proxy_for_model is the non-deferred
        # model.
        model = opts.proxy_for_model
    # The app registry wants a unique name for each model, otherwise the new
    # class won't be created (we get an exception). Therefore, we generate
    # the name using the passed in attrs. It's OK to reuse an existing class
    # object if the attrs are identical.
    name = "%s_Deferred_%s" % (model.__name__, '_'.join(sorted(attrs)))
    name = utils.truncate_name(name, 80, 32)

    try:
        return opts.apps.get_model(model._meta.app_label, name)

    except LookupError:

        class Meta:
            proxy = True
            apps = opts.apps
            app_label = opts.app_label

        overrides = {attr: DeferredAttribute(attr, model) for attr in attrs}
        overrides["Meta"] = Meta
        overrides["__module__"] = model.__module__
        overrides["_deferred"] = True
        return type(str(name), (model,), overrides)


 </s> add  </s> remove ``field_names`` are in the same order as the ``values``, so it is possible to
use ``cls(**(zip(field_names, values)))`` to instantiate the object. If all
of the model's fields are present, then ``values`` are guaranteed to be in
the order ``__init__()`` expects them. That is, the instance can be created
by ``cls(*values)``. It is possible to check if all fields are present by
consulting ``cls._deferred`` - if ``False``, then all fields have been loaded
from the database.
 </s> add ``field_names`` are in the same order as the ``values``. If all of the model's
fields are present, then ``values`` are guaranteed to be in the order
``__init__()`` expects them. That is, the instance can be created by
``cls(*values)``. If any fields are deferred, they won't appear in
``field_names``. In that case, assign a value of ``django.db.models.DEFERRED``
to each of the missing fields. </s> remove         if self.model._deferred:
            # Deferred model will not be found from the app registry. This
            # could be fixed by reconstructing the deferred model on unpickle.
            raise RuntimeError("Fields of deferred models can't be reduced")
 </s> add  </s> remove         count = 0
        for field in obj._meta.fields:
            if isinstance(obj.__class__.__dict__.get(field.attname), DeferredAttribute):
                count += 1
 </s> add         count = len(obj.get_deferred_fields()) </s> remove def simple_class_factory(model, attrs):
    """
    Needed for dynamic classes.
    """
    return model


def model_unpickle(model_id, attrs, factory):
 </s> add def model_unpickle(model_id):
          self.assertIsInstance(
              list(SimpleItem.objects.annotate(Count('feature')).only('name')),
              list)
  






















      @override_settings(SESSION_SERIALIZER='django.contrib.sessions.serializers.PickleSerializer')
      def test_ticket_12163(self):
          # Test for #12163 - Pickling error saving session with unsaved model
          # instances.
          SESSION_KEY = '2b1189a188b44ad18c35e1baac6ceead'
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Fixed #26207 -- Replaced dynamic classes with non-data descriptors for deferred instance loading. 
tests/defer_regress/tests.py