﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34490	Tests with mirror database not working as expected	Andrés Fernández	nobody	"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."	Bug	closed	Testing framework	4.2	Normal	invalid			Unreviewed	0	0	0	0	0	0
