#36915: Add support for select_for_update for implicit transactions
-------------------------------------+-------------------------------------
Reporter: David | Owner: MANAS
Type: | MADESHIYA
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by MANAS MADESHIYA):
PR: https://github.com/django/django/pull/20773
Problem:
select_for_update() raises TransactionManagementError when used
as a subquery inside .update() even though the DML statement
creates an implicit transaction at the database level.
Example:
MyModel.objects.filter(
pk__in=MyModel.objects.filter(...).select_for_update()
).update(my_col=...)
# Previously raised TransactionManagementError
# Now works correctly
Fix:
Modified the check in compiler.py to skip the error when
select_for_update is used as a subquery inside a DML statement
by adding "and not self.query.subquery" condition.
Changes:
- django/db/models/sql/compiler.py
- tests/select_for_update/tests.py
--
Ticket URL: <https://code.djangoproject.com/ticket/36915#comment:3>
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 visit
https://groups.google.com/d/msgid/django-updates/0107019c99274c62-743b8483-cf1b-48ca-8401-9f8a950c7a57-000000%40eu-central-1.amazonses.com.