[Django] #34490: Tests with mirror database not working as expected

35 views
Skip to first unread message

Django

unread,
Apr 13, 2023, 2:26:02 PM4/13/23
to django-...@googlegroups.com
#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.

Django

unread,
Apr 13, 2023, 2:44:15 PM4/13/23
to django-...@googlegroups.com
#34490: Tests with mirror database not working as expected
-------------------------------------+-------------------------------------
Reporter: andres-fernandez- | Owner: nobody
fuks |
Type: Bug | Status: closed

Component: Testing framework | Version: 4.2
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* status: new => closed
* resolution: => invalid


Comment:

Hello Andres!

Thank you for your report, though I think this request for help would be
best handled in any of the django users groups. You could either join the
Django Forum or the django-users mailing list, and send details about your
issue (see [[https://docs.djangoproject.com/en/4.2/internals/contributing
/#join-the-django-community|this link]] for more details).

I'll be closing this issue as Invalid, but if you find out that this is
really a bug in Django itself, feel free to re-open this ticket with steps
to reproduce the problem.

--
Ticket URL: <https://code.djangoproject.com/ticket/34490#comment:1>

Reply all
Reply to author
Forward
0 new messages