Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.1.X] Fixed #11936 -- Removed deferred models from the list returne…

…d by the app_cache. Thanks to ryszard for the report, and clamothe for the initial patch.

Backport of r11938 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11942 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7d6213e0aa70340f4e3439abd43bc98427493bd8 1 parent b15d762
Russell Keith-Magee freakboy3742 authored
20 django/db/models/loading.py
View
@@ -131,19 +131,27 @@ def get_app_errors(self):
self._populate()
return self.app_errors
- def get_models(self, app_mod=None):
+ def get_models(self, app_mod=None, include_deferred=False):
"""
Given a module containing models, returns a list of the models.
Otherwise returns a list of all installed models.
+
+ By default, models created to satisfy deferred attribute
+ queries are *not* included in the list of models. However, if
+ you specify include_deferred, they will be.
"""
self._populate()
if app_mod:
- return self.app_models.get(app_mod.__name__.split('.')[-2], SortedDict()).values()
+ app_list = [self.app_models.get(app_mod.__name__.split('.')[-2], SortedDict())]
else:
- model_list = []
- for app_entry in self.app_models.itervalues():
- model_list.extend(app_entry.values())
- return model_list
+ app_list = self.app_models.itervalues()
+ model_list = []
+ for app in app_list:
+ model_list.extend(
+ model for model in app.values()
+ if (not model._deferred or include_deferred)
+ )
+ return model_list
def get_model(self, app_label, model_name, seed_cache=True):
"""
6 tests/modeltests/defer/models.py
View
@@ -183,10 +183,4 @@ def count_delayed_fields(obj, debug=False):
>>> obj.name = "bb"
>>> obj.save()
-# Finally, we need to flush the app cache for the defer module.
-# Using only/defer creates some artifical entries in the app cache
-# that messes up later tests. Purge all entries, just to be sure.
->>> from django.db.models.loading import cache
->>> cache.app_models['defer'] = {}
-
"""}
13 tests/regressiontests/defer_regress/models.py
View
@@ -132,11 +132,14 @@ def __unicode__(self):
>>> i2._deferred # Item must still be non-deferred
False
-# Finally, we need to flush the app cache for the defer module.
-# Using only/defer creates some artifical entries in the app cache
-# that messes up later tests. Purge all entries, just to be sure.
->>> from django.db.models.loading import cache
->>> cache.app_models['defer_regress'] = {}
+# Regression for #11936 - loading.get_models should not return deferred models by default.
+>>> from django.db.models.loading import get_models
+>>> sorted(get_models(models.get_app('defer_regress')), key=lambda obj: obj.__class__.__name__)
+[<class 'regressiontests.defer_regress.models.Item'>, <class 'regressiontests.defer_regress.models.RelatedItem'>, <class 'regressiontests.defer_regress.models.Child'>, <class 'regressiontests.defer_regress.models.Leaf'>]
+
+>>> sorted(get_models(models.get_app('defer_regress'), include_deferred=True), key=lambda obj: obj.__class__.__name__)
+[<class 'regressiontests.defer_regress.models.Item'>, <class 'regressiontests.defer_regress.models.RelatedItem'>, <class 'regressiontests.defer_regress.models.Child'>, <class 'regressiontests.defer_regress.models.Leaf'>, <class 'regressiontests.defer_regress.models.Item_Deferred_text_value'>, <class 'regressiontests.defer_regress.models.Item_Deferred_name_other_value_text'>, <class 'regressiontests.defer_regress.models.RelatedItem_Deferred_item_id'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_second_child_value'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_name_value'>, <class 'regressiontests.defer_regress.models.Item_Deferred_name'>, <class 'regressiontests.defer_regress.models.Item_Deferred_other_value_text_value'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_value'>]
"""
}
+
Please sign in to comment.
Something went wrong with that request. Please try again.