On Sunday 02 February 2014 23:08:05 Wlodek wrote:
> Hi all,
> 
> I have doubt about mentioned test. Is it correct?
> 

The test is correct for the backends in core.

> As context manager "constraint_checks_disabled" enables
> constraint checking upon exit which is before end of transaction (rollback)
> there will/should be IntegrityError raised?
> 

That depends on the backend. For MySQL, you can (and the backend does) enable 
the constraints without checking them on existing data, so no error is raised. 

I don't know if you can force checks while enabling constraints on MySQL; you 
can (and should) on MSSQL, which AFAIR doesn't have deferrable FKs -- and then 
the test would fail. Although MSSQL is not in core, we should probably try 
harder to be friendly towards it.

> As I understand this test passes for oracle/postgres because there
> is no implementation for "enable/disable_constraint_checking" for those
> backends?
> 

Not exactly. The methods, as you say, do nothing -- so you could expect the 
test to fail because the checks are never turned off. But Postgres and Oracle 
have deferrable FKs -- which means the checks for FK constraints are only done 
at transaction commit time; since the transaction is rolled back, nothing 
fails.

There is one thing in the test (also the preceding test) which could be seen 
as a little misleading -- the line "transaction.set_rollback(True)" only gets 
executed when the test passes, because self.fail(...) raises an exception. You 
don't see that in the code -- you would if it were in an "else" block" -- but 
if you're familiar with tests, it shouldn't surprise you much.

HTH,
        Shai.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/201402031957.09468.shai%40platonix.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to