  # MISC #
  ########
  
  
  def simple_class_factory(model, attrs):
      """
      Needed for dynamic classes.
      """
      return model
  
  
  def model_unpickle(model_id, attrs, factory):
      """
      Used to unpickle Model subclasses with deferred fields.
      """
      if isinstance(model_id, tuple):
          model = apps.get_model(*model_id)
 
</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         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             if isinstance(self.__class__.__dict__.get(f.attname), DeferredAttribute)
 </s> add             if f.attname not in self.__dict__ </s> remove     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)))

 </s> add  </s> remove     cls = factory(model, attrs)
    return cls.__new__(cls)
 </s> add     return model.__new__(model)
def model_unpickle(model_id):
  # MISC #
  ########
  
  
def model_unpickle(model_id):
def model_unpickle(model_id):
def model_unpickle(model_id):
def model_unpickle(model_id):
def model_unpickle(model_id):
def model_unpickle(model_id):
def model_unpickle(model_id):
def model_unpickle(model_id):
      """
      Used to unpickle Model subclasses with deferred fields.
      """
      if isinstance(model_id, tuple):
          model = apps.get_model(*model_id)
keep keep keep keep 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