#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 | Owner: Jacob
| Walls
Type: Bug | Status: assigned
Component: Core | Version: dev
(Serialization) |
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
-------------------------------------+-------------------------------------
Comment (by Jacob Walls):
Thanks for the idea, I had a look. Turns out minimally adjusting comment:5
to run (by adding `.creation` in one of a couple places) doesn't fix OP's
reproduction. It also doesn't pass the unit test I had written to go with
comment:3 below, but that is to be expected since the test has nothing to
do with `setup_databases()`. (It does pass with comment:3.)
{{{#!diff
diff --git a/tests/backends/base/test_creation.py
b/tests/backends/base/test_creation.py
index 7e760e8884..84eb3f4a5f 100644
--- a/tests/backends/base/test_creation.py
+++ b/tests/backends/base/test_creation.py
@@ -172,6 +172,7 @@ class TestDbCreationTests(SimpleTestCase):
class TestDeserializeDbFromString(TransactionTestCase):
available_apps = ["backends"]
+ databases = {"default", "other"}
def test_circular_reference(self):
# deserialize_db_from_string() handles circular references.
@@ -267,6 +268,24 @@ class
TestDeserializeDbFromString(TransactionTestCase):
self.assertIn('"model": "backends.schoolclass"', data)
self.assertIn(f'"schoolclasses": [{sclass.pk}]', data)
+ def test_serialize_db_to_string_with_m2m_field_and_router(self):
+ class OtherRouter:
+ def db_for_read(self, model, **hints):
+ return "other"
+
+ with override_settings(DATABASE_ROUTERS=[OtherRouter()]):
+ obj1 = Object.objects.create()
+ obj2 = Object.objects.create()
+ obj2.related_objects.set([obj1])
+ with
mock.patch("django.db.migrations.loader.MigrationLoader") as loader:
+ # serialize_db_to_string() serializes only migrated apps,
so mark
+ # the backends app as migrated.
+ loader_instance = loader.return_value
+ loader_instance.migrated_apps = {"backends"}
+ data = connection.creation.serialize_db_to_string()
+ self.assertIn(f'"related_objects": [{obj1.pk}]', data)
+ # Test serialize() directly, in all four cases (json/xml, natural
key/without)
+
class SkipTestClass:
def skip_function(self):
}}}
My plan was to repeat these tests with plain calls to `serialize()` in
tests/serializers and test all four cases (json vs. xml, natural key vs.
without). If this test is fair, wouldn't this be an issue with the
serializers? Maybe I'm missing a reason this test isn't realistic.
--
Ticket URL: <https://code.djangoproject.com/ticket/35967#comment:7>
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/01070193b3bba4ac-c177c608-e46c-4171-baea-f7a8c0e5c4b2-000000%40eu-central-1.amazonses.com.