Still disagree. Beign correct you must mean it passes while
I would say it is incorrect conceptually. besides one might expect it to
work on other backends as well, which is exactly what I try to do,
not only core backends.
I understand that in some backends you can declare default/initial constraint
deferability which is set by django to "deferred" by default because that is
what we need most of the time, ie. constraint checks at the commit.
But one might ask two questions
1. What are context manager "constraint_checks_disabled", and methods
"disable/enable_constraint_checking" supposed to do? If nothing than
they can be removed.
2. What if the backend used doesn't have default/initial constraint deferrability
but has transaction level set contraint checking?
I would expect that if the backend/database used can control constraint checking
(defere it or enforce) then "constraint_checks_disabled" should implement it.
Not only if a backend doesn't have default/initial constraint deferrability when
those 3 methods are the only means to control constraint but even if it has
initial deferrability those should be implemented. You may not use them
which one will almost always do but if you do they should work as supposed.
As "constraint_checks_disabled" is expected to disable contraint checking
for a given block of statements and enforce them at the end inside
a transation (as savepoints do for commits) and in the test
we are checking that IntegrityError is not raised then in implemented (not empty)
constraint_checks_disabled and disable/enable_constraint_checking you should
use it in expected way, ie. ensure that constraints are not vialated at the exit
from context manager, ie. something like that:
try:
with connection.constraint_checks_disabled():
a.save()
a.save()
except IntegrityError:
self.fail("IntegrityError should not have occurred.")
That should work as expected in all cases.
The same goes for two other tests in this test case.
Regards
Wlodek