#34490: Tests with mirror database not working as expected
-------------------------------------------------+------------------------
               Reporter:  andres-fernandez-fuks  |          Owner:  nobody
                   Type:  Bug                    |         Status:  new
              Component:  Testing framework      |        Version:  4.2
               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                      |
-------------------------------------------------+------------------------
 Hello. I am using TransactionTestCases to perform tests using a primary-
 replica database architecture. I followed the instructions here
 [https://docs.djangoproject.com/en/4.2/topics/testing/advanced/#testing-
 primary-replica-configurations] to create this architecture for testing.
 However, I encounter some issues:

 * Fixtures cannot be loaded: foreign keys are not found. From what I see,
 loaddata command is placed inside a transaction.atomic block, so that
 would make sense. However, in a different, more simple project, with a
 couple of models and fixtures with foreign keys, fixtures DO work, so I'm
 not sure what the issue is.
 * If I try to manually load the fixtures in setUp (calling loaddata
 command manually), something strange happens: for the first test of a
 given TransactionTestCase, I have the same issue that above: any fixture
 referencing an afore loaded object loaded through a FK fails because said
 object is not found. However, the manual fixture loading does work for the
 rest of the tests. It's hard to understand why.
 * Some tests fail because the replica database does not find an object.
 For example, I create an object and then try to retrieve it, and the
 object is not found. Through debugging, the object is correctly created in
 the primary db, but for some reason not replicated in the other one. A
 very strange thing is that this happens when I run this TestCase in
 particular, when I run all my tests, that same test passes.

 There is something not deterministic about tests failing when using this
 architecture, and I believe it mainly has to do with data not being
 replicated for some reason. I believed I followed the instructions
 correctly, using TransactionTestCase instead of TestCase, and setting up
 the replica to mirror the default database. Like I said, in my other
 simple project, things do work as expected: non of the above issues is
 raised (using the same Python, PostgreSQL and libraries' versions). Any
 help would be appreciated.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34490>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701877bde00c2-546ade06-25d9-4175-a510-aedb411d0c7c-000000%40eu-central-1.amazonses.com.

Reply via email to