[Django]-TransactionManagementError while running tests, but can't find atomic block

4๐Ÿ‘

โœ…

I tracked down the change by rolling back commits until the tests passed and comparing what changed. It turned out that it was adding a post save signal handler to auto-create a linked model that was the change that stopped tests passing. I have a User model, and a UserProfile model with a OneToOneField pointing at the User model.

The problem was that the tests were often manually creating the UserProfile. Once the post_save handler was added, that would lead to an error of duplicate id for the manually created UserProfile, as the automatically created UserProfile has already used that id. I guess that caused the transaction around the unit test to fail badly, leading to all the other errors.

But that original error was hidden in the noise of the many errors about transactions.

๐Ÿ‘คHamish Downer

Leave a comment