[Django] #33506: bulk_update perform atomic writes against routed db_for_write

21 views
Skip to first unread message

Django

unread,
Feb 9, 2022, 12:49:46 AM2/9/22
to django-...@googlegroups.com
#33506: bulk_update perform atomic writes against routed db_for_write
-------------------------------------+-------------------------------------
Reporter: Simon | Owner: nobody
Charette |
Type: Bug | Status: assigned
Component: Database | Version: 4.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Discovered in https://code.djangoproject.com/ticket/33501#comment:3 but
the summary is that `bulk_update` doesn't set `self._for_write = True`
prior to accessing `self.db` so the latter is actually `db_for_read` and
that includes the `transaction.atomic` block creation.

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

Django

unread,
Feb 9, 2022, 1:24:17 AM2/9/22
to django-...@googlegroups.com
#33506: QuerySet.bulk_update() should perform atomic writes against routed
db_for_write.
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: nobody
Type: Bug | Status: assigned
Component: Database layer | Version: 4.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

* stage: Unreviewed => Accepted


Comment:

Good catch!

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

Django

unread,
Feb 9, 2022, 1:47:07 AM2/9/22
to django-...@googlegroups.com
#33506: QuerySet.bulk_update() should perform atomic writes against routed
db_for_write.
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: nobody
Type: Bug | Status: assigned

Component: Database layer | Version: 4.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


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

Django

unread,
Feb 9, 2022, 5:25:07 AM2/9/22
to django-...@googlegroups.com
#33506: QuerySet.bulk_update() should perform atomic writes against routed
db_for_write.
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: nobody
Type: Bug | Status: assigned

Component: Database layer | Version: 4.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* stage: Accepted => Ready for checkin


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

Django

unread,
Feb 9, 2022, 5:59:33 AM2/9/22
to django-...@googlegroups.com
#33506: QuerySet.bulk_update() should perform atomic writes against routed
db_for_write.
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: nobody
Type: Bug | Status: closed

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

Keywords: | Triage Stage: Ready for
| 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:"d35ce682e31ea4a86c2079c60721fae171f03d7c" d35ce682]:
{{{
#!CommitTicketReference repository=""
revision="d35ce682e31ea4a86c2079c60721fae171f03d7c"
Fixed #33506 -- Made QuerySet.bulk_update() perform atomic writes against
write database.

The lack of _for_write = True assignment in bulk_update prior to
accessing self.db resulted in the db_for_read database being used to
wrap batched UPDATEs in a transaction.

Also tweaked the batch queryset creation to also ensure they are
executed against the same database as the opened transaction under all
circumstances.

Refs #23646, #33501.
}}}

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

Reply all
Reply to author
Forward
0 new messages