Re: FK constraints are not checked at the end of nested atomic blocks

2015-12-30 Thread Shai Berger
On Thursday 31 December 2015 06:31:40 Gavin Wahl wrote: > I understand that a database is invalid or invalid as a whole, which is why > you don't need to check constraints until transaction commit (when the > transaction becomes visible to the world). Why do you want to bundle > constraint checking

Re: FK constraints are not checked at the end of nested atomic blocks

2015-12-30 Thread Gavin Wahl
I understand that a database is invalid or invalid as a whole, which is why you don't need to check constraints until transaction commit (when the transaction becomes visible to the world). Why do you want to bundle constraint checking with a savepoint release though? They seem logically unrelated.

Re: FK constraints are not checked at the end of nested atomic blocks

2015-12-30 Thread Shai Berger
Hi, On Tuesday 29 December 2015 19:40:44 Gavin Wahl wrote: > What does it even mean for constraints to be checked at savepoint commit? I > would expect this to not cause any errors: > > with atomic(): > # insert invalid fk > with atomic(check_deferred_constraints=True): >

Re: FK constraints are not checked at the end of nested atomic blocks

2015-12-29 Thread Gavin Wahl
What does it even mean for constraints to be checked at savepoint commit? I would expect this to not cause any errors: with atomic(): # insert invalid fk with atomic(check_deferred_constraints=True): # do stuff that doesn't invalidate any contraints # delet

Re: FK constraints are not checked at the end of nested atomic blocks

2015-12-27 Thread Anssi Kääriäinen
On Tuesday, December 22, 2015 at 1:20:23 AM UTC+2, Shai Berger wrote: > > > We could add a documented API to check wanted models for foreign key > > constraint violations (.check_constraints(Model1, Model2) would be a > > likely API). Then lets just document that depending on the database > > th

Re: FK constraints are not checked at the end of nested atomic blocks

2015-12-21 Thread Shai Berger
On Monday 21 December 2015 19:42:22 Anssi Kääriäinen wrote: > The only generic way to check the constraints is to run through all > tables and their constraints. The constraint check itself is a check > that a matching row in a foreign table exists for each row of the > checked table. This means th

Re: FK constraints are not checked at the end of nested atomic blocks

2015-12-21 Thread Anssi Kääriäinen
The only generic way to check the constraints is to run through all tables and their constraints. The constraint check itself is a check that a matching row in a foreign table exists for each row of the checked table. This means that the check could take hours on large databases. In addition the ch

Re: FK constraints are not checked at the end of nested atomic blocks

2015-12-21 Thread Shai Berger
While expensive operations may be unsuitable for general consumption, this kind of validation may be useful in special cases and offline jobs, notably in "data" migrations. So I think we should consider supporting them via an argument to atomic(). Be that as it may, so long as we do not plan to

Re: FK constraints are not checked at the end of nested atomic blocks

2015-12-21 Thread Aymeric Augustin
2015-12-21 13:12 GMT+01:00 Anssi Kääriäinen : > The check_constraints operation is extremely expensive, and not suitable > for use at the end of savepoints. Ah. Too bad! -- Aymeric. -- You received this message because you are subscribed to the Google Groups "Django developers (Contributio

Re: FK constraints are not checked at the end of nested atomic blocks

2015-12-21 Thread Aymeric Augustin
Hello, When a question of "should Django do A or B here?" comes up, adding a setting to let the user choose is the last resort, because it's really a cop-out, not the default choice. Django explicitly creates FKs on PostgreSQL as DEFERRABLE INITIALLY DEFERRED in order not to check constraints unt

Re: FK constraints are not checked at the end of nested atomic blocks

2015-12-21 Thread Anssi Kääriäinen
The check_constraints operation is extremely expensive, and not suitable for use at the end of savepoints. The reason why we use deferred constraints by default is mostly historical. We do need deferred constraints for fixture loading, and applications might rely on current implementation, but we

FK constraints are not checked at the end of nested atomic blocks

2015-12-21 Thread Артём Клименко
I opened this ticket https://code.djangoproject.com/ticket/25955 The last proposal for the improvement https://code.djangoproject.com/ticket/25955#comment:5 add parameter in OPTIONS DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', # ... '