diff options
| author | Simon Charette <charette.s@gmail.com> | 2023-05-31 18:04:17 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-06-01 19:50:47 +0100 |
| commit | 2cf76f2d5d1aa16acfadaf53db3d30128a34b088 (patch) | |
| tree | d52375c65c679cb43eadeca9b917ec31a45fa630 /django/db/models/sql | |
| parent | d9e701879612312391c0dca5c158b79a1dabcf18 (diff) | |
Fixed #34612 -- Fixed QuerySet.only() crash on reverse relationships.
Regression in b3db6c8dcb5145f7d45eff517bcd96460475c879.
Thanks Ian Cubitt for the report.
This also corrected test_inheritance_deferred2() test which was
previously properly defined and marked as an expected failure but was
then wrongly adjusted to mask the lack of support for per-alias
deferral that was fixed by #21204.
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 781dfd5499..772ba13419 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -779,7 +779,13 @@ class Query(BaseExpression): # Only include fields mentioned in the mask. for field_name, field_mask in mask.items(): field = opts.get_field(field_name) - field_select_mask = select_mask.setdefault(field, {}) + # Retrieve the actual field associated with reverse relationships + # as that's what is expected in the select mask. + if field in opts.related_objects: + field_key = field.field + else: + field_key = field + field_select_mask = select_mask.setdefault(field_key, {}) if field_mask: if not field.is_relation: raise FieldError(next(iter(field_mask))) |
