          only module-level classes can be pickled by the default path.
          """
          data = self.__dict__
          data[DJANGO_VERSION_PICKLE_KEY] = get_version()
          if not self._deferred:
              class_id = self._meta.app_label, self._meta.object_name
              return model_unpickle, (class_id, [], simple_class_factory), data
          defers = []
          for field in self._meta.fields:
              if isinstance(self.__class__.__dict__.get(field.attname),
                            DeferredAttribute):
                  defers.append(field.attname)
          model = self._meta.proxy_for_model
          class_id = model._meta.app_label, model._meta.object_name
          return (model_unpickle, (class_id, defers, deferred_class_factory), data)
  
      def __setstate__(self, state):
          msg = None
          pickled_version = state.get(DJANGO_VERSION_PICKLE_KEY)
          if pickled_version:
 
</s> remove         model = obj._meta.proxy_for_model if obj._deferred else obj.__class__
        data = OrderedDict([('model', force_text(model._meta))])
 </s> add         data = OrderedDict([('model', force_text(obj._meta))]) </s> remove         if self._deferred:
            non_deferred_model = self._meta.proxy_for_model
        else:
            non_deferred_model = self.__class__
        db_instance_qs = non_deferred_model._default_manager.using(db).filter(pk=self.pk)
 </s> add         db_instance_qs = self.__class__._default_manager.using(db).filter(pk=self.pk) </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     def __set__(self, instance, value):
        """
        Deferred loading attributes can be set normally (which means there will
        never be a database lookup involved.
        """
        instance.__dict__[self.field_name] = value

 </s> add  </s> remove         non_deferred_model = instance._meta.proxy_for_model
        opts = non_deferred_model._meta

        assert instance is not None
 </s> add         if instance is None:
            return self
        opts = instance._meta
        class_id = self._meta.app_label, self._meta.object_name
        return model_unpickle, (class_id,), data
          only module-level classes can be pickled by the default path.
          """
          data = self.__dict__
          data[DJANGO_VERSION_PICKLE_KEY] = get_version()
        class_id = self._meta.app_label, self._meta.object_name
        return model_unpickle, (class_id,), data
        class_id = self._meta.app_label, self._meta.object_name
        return model_unpickle, (class_id,), data
        class_id = self._meta.app_label, self._meta.object_name
        return model_unpickle, (class_id,), data
        class_id = self._meta.app_label, self._meta.object_name
        return model_unpickle, (class_id,), data
        class_id = self._meta.app_label, self._meta.object_name
        return model_unpickle, (class_id,), data
        class_id = self._meta.app_label, self._meta.object_name
        return model_unpickle, (class_id,), data
        class_id = self._meta.app_label, self._meta.object_name
        return model_unpickle, (class_id,), data
        class_id = self._meta.app_label, self._meta.object_name
        return model_unpickle, (class_id,), data
        class_id = self._meta.app_label, self._meta.object_name
        return model_unpickle, (class_id,), data
        class_id = self._meta.app_label, self._meta.object_name
        return model_unpickle, (class_id,), data
        class_id = self._meta.app_label, self._meta.object_name
        return model_unpickle, (class_id,), data
  
      def __setstate__(self, state):
          msg = None
          pickled_version = state.get(DJANGO_VERSION_PICKLE_KEY)
          if pickled_version:
keep keep keep keep 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. 
django/db/models/base.py