[Django] #31866: Proxy model is ignored when referenced in select_for_update's 'of' parameter

22 views
Skip to first unread message

Django

unread,
Aug 8, 2020, 1:14:42 AM8/8/20
to django-...@googlegroups.com
#31866: Proxy model is ignored when referenced in select_for_update's 'of'
parameter
-------------------------------------+-------------------------------------
Reporter: Daniel | Owner: nobody
Hillier |
Type: Bug | Status: new
Component: Database | Version: 3.1
layer (models, ORM) | Keywords: proxy
Severity: Normal | select_for_update
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When referring to a proxy model as a FK in a `select_for_update()` call,
the proxy model's table is silently omitted from the `FOR UPDATE` clause
in the resulting SQL.

Also, if a model has a FK to a proxy model, the `FieldError` that is
supposed to be raised when an any inappropriate field is found in a
`select_for_update()` call will crash with `AttributeError: 'NoneType'
object has no attribute 'name'` .

Tested with postgres but I don't think this is specific to that db.

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

Django

unread,
Aug 8, 2020, 1:22:59 AM8/8/20
to django-...@googlegroups.com
#31866: Proxy model is ignored when referenced in select_for_update's 'of'
parameter
-------------------------------------+-------------------------------------
Reporter: Daniel Hillier | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: proxy | Triage Stage:
select_for_update | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Daniel Hillier):

Created branch with failing tests here:
https://github.com/danifus/django/tree/b31866

--
Ticket URL: <https://code.djangoproject.com/ticket/31866#comment:1>

Django

unread,
Aug 8, 2020, 7:53:45 AM8/8/20
to django-...@googlegroups.com
#31866: Proxy model is ignored when referenced in select_for_update's 'of'
parameter
-------------------------------------+-------------------------------------
Reporter: Daniel Hillier | Owner: Daniel
| Hillier
Type: Bug | Status: assigned

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: proxy | Triage Stage:
select_for_update | Unreviewed
Has patch: 1 | Needs documentation: 0

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

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


Comment:

Submitted a pull request with a fix:
https://github.com/django/django/pull/13283

--
Ticket URL: <https://code.djangoproject.com/ticket/31866#comment:2>

Django

unread,
Aug 8, 2020, 9:45:42 PM8/8/20
to django-...@googlegroups.com
#31866: Proxy model is ignored when referenced in select_for_update's 'of'
parameter
-------------------------------------+-------------------------------------
Reporter: Daniel Hillier | Owner: Daniel
| Hillier
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: proxy | Triage Stage: Accepted
select_for_update |
Has patch: 1 | Needs documentation: 0

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

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/31866#comment:3>

Django

unread,
Aug 8, 2020, 9:48:52 PM8/8/20
to django-...@googlegroups.com
#31866: Proxy model is ignored when referenced in select_for_update's 'of'
parameter
-------------------------------------+-------------------------------------
Reporter: Daniel Hillier | Owner: Daniel
| Hillier
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: proxy | Triage Stage: Ready for
select_for_update | checkin
Has patch: 1 | Needs documentation: 0

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

* stage: Accepted => Ready for checkin


Comment:

Patch is looking good to me. Thanks for your great patch and test Daniel.

--
Ticket URL: <https://code.djangoproject.com/ticket/31866#comment:4>

Django

unread,
Aug 9, 2020, 1:34:02 AM8/9/20
to django-...@googlegroups.com
#31866: Proxy model is ignored when referenced in select_for_update's 'of'
parameter
-------------------------------------+-------------------------------------
Reporter: Daniel Hillier | Owner: Daniel
| Hillier
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: proxy | Triage Stage: Ready for
select_for_update | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Daniel Hillier):

Thanks for your help! I've squashed the commits and it is good to go.

--
Ticket URL: <https://code.djangoproject.com/ticket/31866#comment:5>

Django

unread,
Aug 11, 2020, 3:35:21 AM8/11/20
to django-...@googlegroups.com
#31866: Proxy model is ignored when referenced in select_for_update's 'of'
parameter
-------------------------------------+-------------------------------------
Reporter: Daniel Hillier | Owner: Daniel
| Hillier
Type: Bug | Status: assigned
Component: Database layer | Version: 2.2

(models, ORM) |
Severity: Normal | Resolution:
Keywords: proxy | Triage Stage: Ready for
select_for_update | checkin
Has patch: 1 | Needs documentation: 0

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

* version: 3.1 => 2.2


Comment:

This qualifies for a backport as a data loss bug.

--
Ticket URL: <https://code.djangoproject.com/ticket/31866#comment:6>

Django

unread,
Aug 11, 2020, 6:35:39 AM8/11/20
to django-...@googlegroups.com
#31866: Proxy model is ignored when referenced in select_for_update's 'of'
parameter
-------------------------------------+-------------------------------------
Reporter: Daniel Hillier | Owner: Daniel
| Hillier
Type: Bug | Status: closed

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

Keywords: proxy | Triage Stage: Ready for
select_for_update | 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:"60626162f76f26d32a38d18151700cb041201fb3" 6062616]:
{{{
#!CommitTicketReference repository=""
revision="60626162f76f26d32a38d18151700cb041201fb3"
Fixed #31866 -- Fixed locking proxy models in
QuerySet.select_for_update(of=()).
}}}

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

Django

unread,
Aug 11, 2020, 6:35:55 AM8/11/20
to django-...@googlegroups.com
#31866: Proxy model is ignored when referenced in select_for_update's 'of'
parameter
-------------------------------------+-------------------------------------
Reporter: Daniel Hillier | Owner: Daniel
| Hillier
Type: Bug | Status: closed
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: proxy | Triage Stage: Ready for
select_for_update | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"f139372491b35d36748f0fb24146fb20f7e1eead" f139372]:
{{{
#!CommitTicketReference repository=""
revision="f139372491b35d36748f0fb24146fb20f7e1eead"
[3.1.x] Fixed #31866 -- Fixed locking proxy models in
QuerySet.select_for_update(of=()).

Backport of 60626162f76f26d32a38d18151700cb041201fb3 from master
}}}

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

Django

unread,
Aug 11, 2020, 6:36:18 AM8/11/20
to django-...@googlegroups.com
#31866: Proxy model is ignored when referenced in select_for_update's 'of'
parameter
-------------------------------------+-------------------------------------
Reporter: Daniel Hillier | Owner: Daniel
| Hillier
Type: Bug | Status: closed
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: proxy | Triage Stage: Ready for
select_for_update | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"784ed4ada112753c35dd7c6b85686ad1d935b65d" 784ed4ad]:
{{{
#!CommitTicketReference repository=""
revision="784ed4ada112753c35dd7c6b85686ad1d935b65d"
[3.0.x] Fixed #31866 -- Fixed locking proxy models in
QuerySet.select_for_update(of=()).

Backport of 60626162f76f26d32a38d18151700cb041201fb3 from master
}}}

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

Django

unread,
Aug 11, 2020, 6:36:50 AM8/11/20
to django-...@googlegroups.com
#31866: Proxy model is ignored when referenced in select_for_update's 'of'
parameter
-------------------------------------+-------------------------------------
Reporter: Daniel Hillier | Owner: Daniel
| Hillier
Type: Bug | Status: closed
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: proxy | Triage Stage: Ready for
select_for_update | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"839f906a23271b24bf435b16575bbbfd0d2ddcf9" 839f906a]:
{{{
#!CommitTicketReference repository=""
revision="839f906a23271b24bf435b16575bbbfd0d2ddcf9"
[2.2.x] Fixed #31866 -- Fixed locking proxy models in
QuerySet.select_for_update(of=()).

Backport of 60626162f76f26d32a38d18151700cb041201fb3 from master
}}}

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

Reply all
Reply to author
Forward
0 new messages