Deferred FKs make TestCase tests unreliable - no FK constraints checks at all!
|Reported by:||zimnyx||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.3|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
- Database backends which have DatabaseFeatures.can_defer_constraint_checks=True including Postgres psycopg2 create deferred FK during syncdb.
- Deferred FK means that in case of ROLLBACK no constraing check is performed - illegal FK values are accepted.
- TestCase is using ROLLBACK to "refresh" database state - you can use illegal FKs in INSERT and UPDATE statemets - no error will be reported, which makes those tests unreliable.
I've noticed that deferred constraints are used by django.db.models.deletion.CASCADE(). Why no to use FK cascades if database supports it, and let user decide which cascades should be set?