#30953: Model Inheritance and select_for_update with 'of'
-------------------------------------+-------------------------------------
Reporter: Abhijeet | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 2.2
layer (models, ORM) | Keywords: race conditions,
Severity: Normal | psql, concurrency, db
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Consider two models A and B with B being a sub model of A. If I have a
select and update that looks like this (assume it all happens inside an
atomic transaction):
{{{
b = B.objects.filter(pk=1).select_for_update(of=('self'))
b = b[0] # Evaluate the query
b.some_field_of_b = b.some_field_of_b + 1
b.save()
}}}
This will cause race conditions. The generated SQL will only lock the
table of A (the super-model) and not of B. As you can see, the field being
updated is of B and not of A. Even though the `SELECT .. FOR UPDATE OF`
might block, the queryset returned will not contain the updated data of
the table of B because the snapshot will not include the updated data
(before a lock is even acquired).
When the `of` parameter for `select_for_update` is supplied, the tables
locked should include those of the sub-models of the `of` fields.
--
Ticket URL: <https://code.djangoproject.com/ticket/30953>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/056.e61de4fbe14151c608c6ccb7cc9366a6%40djangoproject.com.