Re: [Django] #11541: F() expressions don't allow assignment of Foreign Key values on instances

18 views
Skip to first unread message

Django

unread,
Feb 29, 2020, 2:22:47 AM2/29/20
to django-...@googlegroups.com
#11541: F() expressions don't allow assignment of Foreign Key values on instances
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.1-beta
(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 Abhijeet Viswa):

I gave a shot at fixing this ticket. However, I got stuck real fast. F
expressions aren't resolved until the queryset is evaluated. However, the
test to check if the right-value is an instance of the forward relation's
class is performed during assignment. The only solution I could think of
is to defer the test for F expressions until queryset evaluation.

Maintainers, would this be the best approach?

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

Django

unread,
Feb 29, 2020, 2:24:12 AM2/29/20
to django-...@googlegroups.com
#11541: F() expressions don't allow assignment of Foreign Key values on instances
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.1-beta
(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
-------------------------------------+-------------------------------------
Changes (by Abhijeet Viswa):

* cc: Abhijeet Viswa (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/11541#comment:7>

Django

unread,
Mar 1, 2020, 11:26:01 AM3/1/20
to django-...@googlegroups.com
#11541: F() expressions don't allow assignment of Foreign Key values on instances
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.1-beta
(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 Simon Charette):

> The only solution I could think of is to defer the test for F
expressions until queryset evaluation.

Abhijeet, the check can likely be deferred `if hasattr(value,
resolve_expression)`.

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

Django

unread,
Apr 12, 2020, 8:22:28 AM4/12/20
to django-...@googlegroups.com
#11541: F() expressions don't allow assignment of Foreign Key values on instances
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.1-beta
(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 Abhijeet Viswa):

Marten Kenbeek pointed out to me that `F`expression can be assigned to the
`attname` attribute of the Model instance. So,
`test_gmbh.point_of_contact_id` can be assigned `F('ceo')` to have the
intended effect. However, I don't think this is documented. Would
documenting this be enough to close this ticket? Or should F expressions
be assignable to the relation descriptors?

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

Django

unread,
Sep 15, 2022, 10:29:14 AM9/15/22
to django-...@googlegroups.com
#11541: F() expressions don't allow assignment of Foreign Key values on instances
-------------------------------------+-------------------------------------
Reporter: Russell Keith-Magee | Owner: Aman
| Pandey
Type: Bug | Status: assigned

Component: Database layer | Version: 1.1-beta
(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
-------------------------------------+-------------------------------------
Changes (by Aman Pandey):

* owner: nobody => Aman Pandey
* status: new => assigned


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

Reply all
Reply to author
Forward
0 new messages