Opened 2 years ago

Closed 2 years ago

#33506 closed Bug (fixed)

QuerySet.bulk_update() should perform atomic writes against routed db_for_write.

Reported by: Simon Charette Owned by: nobody
Component: Database layer (models, ORM) Version: 4.0
Severity: Normal Keywords:
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

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.

Change History (4)

comment:1 by Mariusz Felisiak, 2 years ago

Summary: bulk_update perform atomic writes against routed db_for_writeQuerySet.bulk_update() should perform atomic writes against routed db_for_write.
Triage Stage: UnreviewedAccepted

Good catch!

comment:2 by Simon Charette, 2 years ago

Has patch: set

comment:3 by Mariusz Felisiak, 2 years ago

Triage Stage: AcceptedReady for checkin

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

Resolution: fixed
Status: assignedclosed

In d35ce682:

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.

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