Re: [Django] #34226: QuerySet.select_related() with multiple filtered relations to the OneToOneField sets the last one.

2 views
Skip to first unread message

Django

unread,
Dec 23, 2022, 6:13:46 AM12/23/22
to django-...@googlegroups.com
#34226: QuerySet.select_related() with multiple filtered relations to the
OneToOneField sets the last one.
-------------------------------------+-------------------------------------
Reporter: zhu | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by zhu):

Replying to [comment:6 Mariusz Felisiak]:
> Thanks! Would you like to prepare a patch?
{{{
diff --git a/django/db/models/sql/compiler.py
b/django/db/models/sql/compiler.py
index 2b66ab12b4..831ef79269 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -1261,7 +1261,7 @@ class SQLCompiler:
)
get_related_klass_infos(klass_info, next_klass_infos)

- def local_setter(obj, from_obj):
+ def local_setter(f, obj, from_obj):
# Set a reverse fk object when relation is non-empty.
if from_obj:
f.remote_field.set_cached_value(from_obj, obj)
@@ -1287,7 +1287,7 @@ class SQLCompiler:
"model": model,
"field": f,
"reverse": True,
- "local_setter": local_setter,
+ "local_setter": partial(local_setter, f),
"remote_setter": partial(remote_setter, name),
"from_parent": from_parent,
}
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34226#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 23, 2022, 6:31:37 AM12/23/22
to django-...@googlegroups.com
#34226: QuerySet.select_related() with multiple filtered relations to the
OneToOneField sets the last one.
-------------------------------------+-------------------------------------
Reporter: zhu | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

Thanks, can you prepare PR (with patch and tests) and
[https://docs.djangoproject.com/en/stable/intro/contributing/#committing-
the-changes-in-the-patch submit it via GitHub]? (docs changes are not
required.)

--
Ticket URL: <https://code.djangoproject.com/ticket/34226#comment:8>

Django

unread,
Dec 23, 2022, 7:15:34 AM12/23/22
to django-...@googlegroups.com
#34226: QuerySet.select_related() with multiple filtered relations to the
OneToOneField sets the last one.
-------------------------------------+-------------------------------------
Reporter: zhu | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by zhu):

Replying to [comment:8 Mariusz Felisiak]:


> Thanks, can you prepare PR (with patch and tests) and
[https://docs.djangoproject.com/en/stable/intro/contributing/#committing-
the-changes-in-the-patch submit it via GitHub]? (docs changes are not
required.)

https://github.com/django/django/pull/16398 done.

--
Ticket URL: <https://code.djangoproject.com/ticket/34226#comment:9>

Django

unread,
Dec 23, 2022, 7:20:45 AM12/23/22
to django-...@googlegroups.com
#34226: QuerySet.select_related() with multiple filtered relations to the
OneToOneField sets the last one.
-------------------------------------+-------------------------------------
Reporter: zhu | Owner: zhu
Type: Bug | Status: assigned

Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => zhu
* status: new => assigned
* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/34226#comment:10>

Django

unread,
Dec 24, 2022, 3:05:45 PM12/24/22
to django-...@googlegroups.com
#34226: QuerySet.select_related() with multiple filtered relations to the
OneToOneField sets the last one.
-------------------------------------+-------------------------------------
Reporter: zhu | Owner: zhu
Type: Bug | Status: assigned
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by GitHub <noreply@…>):

In [changeset:"e07e83589b05e030d1bc0015a758bf3abc4da7cc" e07e8358]:
{{{
#!CommitTicketReference repository=""
revision="e07e83589b05e030d1bc0015a758bf3abc4da7cc"
Refs #34226 -- Renamed local field variables in
SQLCompiler.get_related_selections() to avoid redefinition.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34226#comment:11>

Django

unread,
Dec 27, 2022, 12:37:23 AM12/27/22
to django-...@googlegroups.com
#34226: QuerySet.select_related() with multiple filtered relations to the
OneToOneField sets the last one.
-------------------------------------+-------------------------------------
Reporter: zhu | Owner: zhu
Type: Bug | Status: assigned
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/34226#comment:12>

Django

unread,
Dec 27, 2022, 1:07:44 AM12/27/22
to django-...@googlegroups.com
#34226: QuerySet.select_related() with multiple filtered relations to the
OneToOneField sets the last one.
-------------------------------------+-------------------------------------
Reporter: zhu | Owner: zhu
Type: Bug | Status: closed

Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"bbeeb45161da251bb7297b60d6155e7b4efdbc9f" bbeeb45]:
{{{
#!CommitTicketReference repository=""
revision="bbeeb45161da251bb7297b60d6155e7b4efdbc9f"
Fixed #34226 -- Fixed QuerySet.select_related() with multiple
FilteredRelations to the OneToOneField.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34226#comment:13>

Reply all
Reply to author
Forward
0 new messages