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:
parent
f48855178d
commit
ccab4b041b
|
@ -72,13 +72,13 @@ def inherited_create(pk, klass, data):
|
||||||
# 1) we're testing inheritance, not field behaviour, so none
|
# 1) we're testing inheritance, not field behaviour, so none
|
||||||
# of the field values need to be protected.
|
# of the field values need to be protected.
|
||||||
# 2) saving the child class and having the parent created
|
# 2) saving the child class and having the parent created
|
||||||
# automatically is easier than manually creating both.
|
# automatically is easier than manually creating both.
|
||||||
models.Model.save(instance)
|
models.Model.save(instance)
|
||||||
created = [instance]
|
created = [instance]
|
||||||
for klass,field in instance._meta.parents.items():
|
for klass,field in instance._meta.parents.items():
|
||||||
created.append(klass.objects.get(id=pk))
|
created.append(klass.objects.get(id=pk))
|
||||||
return created
|
return created
|
||||||
|
|
||||||
# A set of functions that can be used to compare
|
# A set of functions that can be used to compare
|
||||||
# test data objects of various kinds
|
# test data objects of various kinds
|
||||||
def data_compare(testcase, pk, klass, data):
|
def data_compare(testcase, pk, klass, data):
|
||||||
|
@ -111,7 +111,7 @@ def inherited_compare(testcase, pk, klass, data):
|
||||||
instance = klass.objects.get(id=pk)
|
instance = klass.objects.get(id=pk)
|
||||||
for key,value in data.items():
|
for key,value in data.items():
|
||||||
testcase.assertEqual(value, getattr(instance,key))
|
testcase.assertEqual(value, getattr(instance,key))
|
||||||
|
|
||||||
# Define some data types. Each data type is
|
# Define some data types. Each data type is
|
||||||
# actually a pair of functions; one to create
|
# actually a pair of functions; one to create
|
||||||
# and one to compare objects of that type
|
# and one to compare objects of that type
|
||||||
|
@ -274,7 +274,7 @@ The end."""),
|
||||||
|
|
||||||
(data_obj, 800, AutoNowDateTimeData, datetime.datetime(2006,6,16,10,42,37)),
|
(data_obj, 800, AutoNowDateTimeData, datetime.datetime(2006,6,16,10,42,37)),
|
||||||
(data_obj, 810, ModifyingSaveData, 42),
|
(data_obj, 810, ModifyingSaveData, 42),
|
||||||
|
|
||||||
(inherited_obj, 900, InheritAbstractModel, {'child_data':37,'parent_data':42}),
|
(inherited_obj, 900, InheritAbstractModel, {'child_data':37,'parent_data':42}),
|
||||||
(inherited_obj, 910, ExplicitInheritBaseModel, {'child_data':37,'parent_data':42}),
|
(inherited_obj, 910, ExplicitInheritBaseModel, {'child_data':37,'parent_data':42}),
|
||||||
(inherited_obj, 920, InheritBaseModel, {'child_data':37,'parent_data':42}),
|
(inherited_obj, 920, InheritBaseModel, {'child_data':37,'parent_data':42}),
|
||||||
|
@ -302,17 +302,19 @@ 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:
|
||||||
instance_count[klass] = klass.objects.count()
|
instance_count[klass] = klass.objects.count()
|
||||||
|
|
||||||
# Add the generic tagged objects to the object list
|
# Add the generic tagged objects to the object list
|
||||||
objects.extend(Tag.objects.all())
|
objects.extend(Tag.objects.all())
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue