mirror of https://github.com/django/django.git
Fixed #12851 -- Corrected the interaction of defer() with select_related(). Thanks to ruosteinen for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12817 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
10d4094b86
commit
3a5dae5ed3
|
@ -1208,7 +1208,7 @@ def get_cached_row(klass, row, index_start, using, max_depth=0, cur_depth=0,
|
|||
next = None
|
||||
# Recursively retrieve the data for the related object
|
||||
cached_row = get_cached_row(f.rel.to, row, index_end, using,
|
||||
max_depth, cur_depth+1, next)
|
||||
max_depth, cur_depth+1, next, only_load=only_load)
|
||||
# If the recursive descent found an object, populate the
|
||||
# descriptor caches relevant to the object
|
||||
if cached_row:
|
||||
|
@ -1237,7 +1237,7 @@ def get_cached_row(klass, row, index_start, using, max_depth=0, cur_depth=0,
|
|||
next = requested[f.related_query_name()]
|
||||
# Recursively retrieve the data for the related object
|
||||
cached_row = get_cached_row(model, row, index_end, using,
|
||||
max_depth, cur_depth+1, next, local_only=True)
|
||||
max_depth, cur_depth+1, next, only_load=only_load, local_only=True)
|
||||
# If the recursive descent found an object, populate the
|
||||
# descriptor caches relevant to the object
|
||||
if cached_row:
|
||||
|
|
|
@ -142,7 +142,7 @@ False
|
|||
[<class 'regressiontests.defer_regress.models.Child'>, <class 'regressiontests.defer_regress.models.Item'>, <class 'regressiontests.defer_regress.models.Leaf'>, <class 'regressiontests.defer_regress.models.RelatedItem'>, <class 'regressiontests.defer_regress.models.ResolveThis'>]
|
||||
|
||||
>>> sorted(get_models(models.get_app('defer_regress'), include_deferred=True), key=lambda obj: obj._meta.object_name)
|
||||
[<class 'regressiontests.defer_regress.models.Child'>, <class 'regressiontests.defer_regress.models.Item'>, <class 'regressiontests.defer_regress.models.Item_Deferred_name'>, <class 'regressiontests.defer_regress.models.Item_Deferred_name_other_value_text'>, <class 'regressiontests.defer_regress.models.Item_Deferred_name_other_value_value'>, <class 'regressiontests.defer_regress.models.Item_Deferred_other_value_text_value'>, <class 'regressiontests.defer_regress.models.Item_Deferred_text_value'>, <class 'regressiontests.defer_regress.models.Leaf'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_child_id_second_child_id_value'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_name_value'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_second_child_value'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_value'>, <class 'regressiontests.defer_regress.models.RelatedItem'>, <class 'regressiontests.defer_regress.models.RelatedItem_Deferred_'>, <class 'regressiontests.defer_regress.models.RelatedItem_Deferred_item_id'>, <class 'regressiontests.defer_regress.models.ResolveThis'>, <class 'regressiontests.defer_regress.models.ResolveThis_Deferred_num'>]
|
||||
[<class 'regressiontests.defer_regress.models.Child'>, <class 'regressiontests.defer_regress.models.Child_Deferred_value'>, <class 'regressiontests.defer_regress.models.Item'>, <class 'regressiontests.defer_regress.models.Item_Deferred_name'>, <class 'regressiontests.defer_regress.models.Item_Deferred_name_other_value_text'>, <class 'regressiontests.defer_regress.models.Item_Deferred_name_other_value_value'>, <class 'regressiontests.defer_regress.models.Item_Deferred_other_value_text_value'>, <class 'regressiontests.defer_regress.models.Item_Deferred_text_value'>, <class 'regressiontests.defer_regress.models.Leaf'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_child_id_second_child_id_value'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_name_value'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_second_child_value'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_value'>, <class 'regressiontests.defer_regress.models.RelatedItem'>, <class 'regressiontests.defer_regress.models.RelatedItem_Deferred_'>, <class 'regressiontests.defer_regress.models.RelatedItem_Deferred_item_id'>, <class 'regressiontests.defer_regress.models.ResolveThis'>, <class 'regressiontests.defer_regress.models.ResolveThis_Deferred_num'>]
|
||||
"""
|
||||
}
|
||||
|
||||
|
|
|
@ -165,4 +165,13 @@ Exercising select_related() with multi-table model inheritance.
|
|||
>>> Item.objects.select_related("child").order_by("name")
|
||||
[<Item: item1>, <Item: item2>]
|
||||
|
||||
# Regression for #12851 - Deferred fields are used correctly if you
|
||||
# select_related a subset of fields.
|
||||
>>> wa = State.objects.create(name="Western Australia", country=australia)
|
||||
>>> _ = Client.objects.create(name='Brian Burke', state=wa, status=active)
|
||||
>>> burke = Client.objects.select_related('state').defer('state__name').get(name='Brian Burke')
|
||||
>>> burke.state.name
|
||||
u'Western Australia'
|
||||
|
||||
"""}
|
||||
|
||||
|
|
Loading…
Reference in New Issue