mirror of https://github.com/django/django.git
[4.2.x] Fixed #34458 -- Fixed QuerySet.defer() crash on attribute names.
Thanks Andrew Cordery for the report. Regression inb3db6c8dcb
. Backport of87c63bd8df
from main
This commit is contained in:
parent
272dc386c2
commit
647920b766
|
@ -702,7 +702,8 @@ class Query(BaseExpression):
|
|||
# by recursively caling this function.
|
||||
for field in opts.concrete_fields:
|
||||
field_mask = mask.pop(field.name, None)
|
||||
if field_mask is None:
|
||||
field_att_mask = mask.pop(field.attname, None)
|
||||
if field_mask is None and field_att_mask is None:
|
||||
select_mask.setdefault(field, {})
|
||||
elif field_mask:
|
||||
if not field.is_relation:
|
||||
|
|
|
@ -9,4 +9,5 @@ Django 4.2.1 fixes several bugs in 4.2.
|
|||
Bugfixes
|
||||
========
|
||||
|
||||
* ...
|
||||
* Fixed a regression in Django 4.2 that caused a crash of ``QuerySet.defer()``
|
||||
when deferring fields by attribute names (:ticket:`34458`).
|
||||
|
|
|
@ -178,6 +178,11 @@ class DeferTests(AssertionMixin, TestCase):
|
|||
obj = ShadowChild.objects.defer("name").get()
|
||||
self.assertEqual(obj.name, "adonis")
|
||||
|
||||
def test_defer_fk_attname(self):
|
||||
primary = Primary.objects.defer("related_id").get()
|
||||
with self.assertNumQueries(1):
|
||||
self.assertEqual(primary.related_id, self.p1.related_id)
|
||||
|
||||
|
||||
class BigChildDeferTests(AssertionMixin, TestCase):
|
||||
@classmethod
|
||||
|
|
Loading…
Reference in New Issue