On Mar 9, 3:52 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> That said, I'm not sure there is much we can do about it. It isn't as
> simple as wrapping the test case with a try/except block; if you are
> explictly testing error states, or the last SQL query in a test is the
> statement that causes a problem, there won't be an exception to catch.
> Essentially what we need in the tearDown is logic that tests:
>
> if cursor is in erroneous state:
>     transaction.rollback()

That is not really adequate. The rollback() needs to occur immediately
after the assertion that causes the error so an
  assertRaises(DatabaseError, ...
can be followed by an assertion that is expected to succeed.

This problem is not limited to tests, either. It also causes problems
with command-line usage and any code that is doing multiple database
updates without an explicit transaction. For example
http://code.djangoproject.com/ticket/852

In this thread
http://groups.google.com/group/django-users/browse_thread/thread/6657812c5798c5e2#
I suggested wrapping Model.save() with a try/except like this:
try:
   ... normal save code
except DatabaseError:
   transaction.rollback_unless_managed()

A more general fix might be to wrap each use of cursor.execute() in a
try/except block such as the above.

Kent
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to