Opened 32 hours ago
Last modified 30 hours ago
#35967 new Bug
TransactionTestCase.serialized_rollback reads from real database rather than test when using read replica for a model instance created in a migration with a ManyToManyField
Reported by: | Jake Howard | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Ryan Cheley | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
(Yes, this is a rather specific bug...)
When:
- Using a database router to create a read-replica database, configured as a
MIRROR
in tests, and - Using
TransactionTestCase.serialized_rollback
, and - Having a model instance created in a migration which has a
ManyToMany
field
The serializer for serialized_rollback
tries to read from the non-test database. If that database doesn't exist yet (for example, in CI), this throws an error:
django.db.utils.OperationalError: no such table: auth_user
If migrations are run (manage.py migrate
), thus creating the tables for the non-test database, tests pass correctly. Prooving it's reading from the wrong connection.
I've created a minimal reproduction of this issue, and confirmed it happens on SQLite, PostgreSQL and Django 4.2, 5.0, 5.1 and main