Fixed #7981 -- Wrap the manual transaction management in the

serializers_regress tests in some "try...finally" blocks. Patch from Leo Soto.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8099 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2008-07-27 03:32:44 +00:00
parent f48855178d
commit ccab4b041b
1 changed files with 20 additions and 16 deletions

View File

@ -302,12 +302,14 @@ def serializerTest(format, self):
objects = []
instance_count = {}
transaction.enter_transaction_management()
transaction.managed(True)
for (func, pk, klass, datum) in test_data:
objects.extend(func[0](pk, klass, datum))
instance_count[klass] = 0
transaction.commit()
transaction.leave_transaction_management()
try:
transaction.managed(True)
for (func, pk, klass, datum) in test_data:
objects.extend(func[0](pk, klass, datum))
instance_count[klass] = 0
transaction.commit()
finally:
transaction.leave_transaction_management()
# Get a count of the number of objects created for each class
for klass in instance_count:
@ -322,11 +324,13 @@ def serializerTest(format, self):
# Flush the database and recreate from the serialized data
management.call_command('flush', verbosity=0, interactive=False)
transaction.enter_transaction_management()
transaction.managed(True)
for obj in serializers.deserialize(format, serialized_data):
obj.save()
transaction.commit()
transaction.leave_transaction_management()
try:
transaction.managed(True)
for obj in serializers.deserialize(format, serialized_data):
obj.save()
transaction.commit()
finally:
transaction.leave_transaction_management()
# Assert that the deserialized data is the same
# as the original source