#35967: 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
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Type: Bug
Status: new | Component: Database
| layer (models, ORM)
Version: dev | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
(Yes, this is a rather specific bug...)
When:
1. Using a database router to create a read-replica database, configured
as a `MIRROR` in tests, and
2. Using `TransactionTestCase.serialized_rollback`, and
3. 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 [https://github.com/RealOrangeOne/django-db-serialize-repro
minimal reproduction] of this issue, and confirmed it happens on SQLite,
PostgreSQL and Django 4.2, 5.0, 5.1 and `main`
--
Ticket URL: <https://code.djangoproject.com/ticket/35967>
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/010701938c2ca368-b85c87ac-58df-419c-b0ae-48577a7f8644-000000%40eu-central-1.amazonses.com.