Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#31866 closed Bug (fixed)

Proxy model is ignored when referenced in select_for_update's 'of' parameter

Reported by: Daniel Hillier Owned by: Daniel Hillier
Component: Database layer (models, ORM) Version: 2.2
Severity: Normal Keywords: proxy select_for_update
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (10)

comment:1 by Daniel Hillier, 4 years ago

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

comment:2 by Daniel Hillier, 4 years ago

Has patch: set
Owner: changed from nobody to Daniel Hillier
Status: newassigned

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

comment:3 by Simon Charette, 4 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Simon Charette, 4 years ago

Triage Stage: AcceptedReady for checkin

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

comment:5 by Daniel Hillier, 4 years ago

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

comment:6 by Mariusz Felisiak, 4 years ago

Version: 3.12.2

This qualifies for a backport as a data loss bug.

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 6062616:

Fixed #31866 -- Fixed locking proxy models in QuerySet.select_for_update(of=()).

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In f139372:

[3.1.x] Fixed #31866 -- Fixed locking proxy models in QuerySet.select_for_update(of=()).

Backport of 60626162f76f26d32a38d18151700cb041201fb3 from master

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 784ed4ad:

[3.0.x] Fixed #31866 -- Fixed locking proxy models in QuerySet.select_for_update(of=()).

Backport of 60626162f76f26d32a38d18151700cb041201fb3 from master

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 839f906a:

[2.2.x] Fixed #31866 -- Fixed locking proxy models in QuerySet.select_for_update(of=()).

Backport of 60626162f76f26d32a38d18151700cb041201fb3 from master

Note: See TracTickets for help on using tickets.
Back to Top