Opened 14 months ago

Closed 14 months ago

Last modified 14 months 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 Changed 14 months ago by Daniel Hillier

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

comment:2 Changed 14 months ago by Daniel Hillier

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 Changed 14 months ago by Simon Charette

Triage Stage: UnreviewedAccepted

comment:4 Changed 14 months ago by Simon Charette

Triage Stage: AcceptedReady for checkin

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

comment:5 Changed 14 months ago by Daniel Hillier

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

comment:6 Changed 14 months ago by Mariusz Felisiak

Version: 3.12.2

This qualifies for a backport as a data loss bug.

comment:7 Changed 14 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 6062616:

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

comment:8 Changed 14 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In f139372:

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

Backport of 60626162f76f26d32a38d18151700cb041201fb3 from master

comment:9 Changed 14 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In 784ed4ad:

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

Backport of 60626162f76f26d32a38d18151700cb041201fb3 from master

comment:10 Changed 14 months ago by Mariusz Felisiak <felisiak.mariusz@…>

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