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