Ticket #11936: fix_r11901.diff

File fix_r11901.diff, 2.3 KB (added by Charlie La Mothe, 15 years ago)

Fix and regression test against r11901

  • django/db/models/loading.py

    diff --git a/django/db/models/loading.py b/django/db/models/loading.py
    index f86b691..bc62aa0 100644
    a b class AppCache(object):  
    132132        self._populate()
    133133        return self.app_errors
    134134
    135     def get_models(self, app_mod=None, include_auto_created=False):
     135    def get_models(self, app_mod=None, include_auto_created=False, include_deferred=False):
    136136        """
    137137        Given a module containing models, returns a list of the models.
    138138        Otherwise returns a list of all installed models.
    class AppCache(object):  
    141141        explicit intermediate table) are not included. However, if you
    142142        specify include_auto_created=True, they will be.
    143143        """
    144         cache_key = (app_mod, include_auto_created)
     144        cache_key = (app_mod, include_auto_created, include_deferred)
    145145        try:
    146146            return self._get_models_cache[cache_key]
    147147        except KeyError:
    class AppCache(object):  
    155155                model_list.extend(app_entry.values())
    156156        if not include_auto_created:
    157157            model_list = filter(lambda o: not o._meta.auto_created, model_list)
     158        if not include_deferred:
     159            model_list = filter(lambda o: not o._deferred, model_list)
    158160        self._get_models_cache[cache_key] = model_list
    159161        return model_list
    160162
  • tests/regressiontests/defer_regress/models.py

    diff --git a/tests/regressiontests/defer_regress/models.py b/tests/regressiontests/defer_regress/models.py
    index a1cd197..23d855b 100644
    a b False  
    132132>>> i2._deferred # Item must still be non-deferred
    133133False
    134134
     135# Regression for #11936 - loading.get_models should not return deferred models by default.
     136>>> from django.db.models.loading import get_models
     137>>> get_models(models.get_app('defer_regress'))
     138[<class 'regressiontests.defer_regress.models.Item'>, <class 'regressiontests.defer_regress.models.RelatedItem'>, <class 'regressiontests.defer_regress.models.Child'>, <class 'regressiontests.defer_regress.models.Leaf'>]
     139
    135140# Finally, we need to flush the app cache for the defer module.
    136141# Using only/defer creates some artifical entries in the app cache
    137142# that messes up later tests. Purge all entries, just to be sure.
Back to Top