django.test.TestCase should flush constraints
|Reported by:||Glenn Maynard||Owned by:|
|Cc:||glenn@…, peruano@…, aball@…, Forest Bond, nperriault@…, jim.dalton@…, graham@…, botondus@…, vlastimil.zima@…, jon.dufresne@…||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In Postgresql, constraints are set DEFERRABLE INITIALLY DEFERRED. This causes it to only check those constraints when the transaction is committed. (This may affect the Oracle backend, too, based on a quick search.)
This causes a problem with TestCase: as they're never committed, many constraint violations can never be triggered.
It's an easy fix: cause SET CONSTRAINTS ALL IMMEDIATE to be executed in TestCase before rolling back the transaction, so any deferred constraints are flushed, and treat an exception from that as a test failure.
I'll work on a patch in a week or so when I have some time. I'm not sure how to test this, since it means testing the testing system itself.
Change History (55)
comment:18 Changed 6 years ago by
|Patch needs improvement:||set|