Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit ccab4b041bded4af529ca2ede4dffab0d95fb5f2 1 parent f488551
Malcolm Tredinnick authored July 27, 2008
36  tests/regressiontests/serializers_regress/tests.py
@@ -72,13 +72,13 @@ def inherited_create(pk, klass, data):
72 72
     #  1) we're testing inheritance, not field behaviour, so none
73 73
     #     of the field values need to be protected.
74 74
     #  2) saving the child class and having the parent created
75  
-    #     automatically is easier than manually creating both. 
  75
+    #     automatically is easier than manually creating both.
76 76
     models.Model.save(instance)
77 77
     created = [instance]
78 78
     for klass,field in instance._meta.parents.items():
79 79
         created.append(klass.objects.get(id=pk))
80 80
     return created
81  
-    
  81
+
82 82
 # A set of functions that can be used to compare
83 83
 # test data objects of various kinds
84 84
 def data_compare(testcase, pk, klass, data):
@@ -111,7 +111,7 @@ def inherited_compare(testcase, pk, klass, data):
111 111
     instance = klass.objects.get(id=pk)
112 112
     for key,value in data.items():
113 113
         testcase.assertEqual(value, getattr(instance,key))
114  
-    
  114
+
115 115
 # Define some data types. Each data type is
116 116
 # actually a pair of functions; one to create
117 117
 # and one to compare objects of that type
@@ -274,7 +274,7 @@ def inherited_compare(testcase, pk, klass, data):
274 274
 
275 275
     (data_obj, 800, AutoNowDateTimeData, datetime.datetime(2006,6,16,10,42,37)),
276 276
     (data_obj, 810, ModifyingSaveData, 42),
277  
-    
  277
+
278 278
     (inherited_obj, 900, InheritAbstractModel, {'child_data':37,'parent_data':42}),
279 279
     (inherited_obj, 910, ExplicitInheritBaseModel, {'child_data':37,'parent_data':42}),
280 280
     (inherited_obj, 920, InheritBaseModel, {'child_data':37,'parent_data':42}),
@@ -302,17 +302,19 @@ def serializerTest(format, self):
302 302
     objects = []
303 303
     instance_count = {}
304 304
     transaction.enter_transaction_management()
305  
-    transaction.managed(True)
306  
-    for (func, pk, klass, datum) in test_data:
307  
-        objects.extend(func[0](pk, klass, datum))
308  
-        instance_count[klass] = 0
309  
-    transaction.commit()
310  
-    transaction.leave_transaction_management()
  305
+    try:
  306
+        transaction.managed(True)
  307
+        for (func, pk, klass, datum) in test_data:
  308
+            objects.extend(func[0](pk, klass, datum))
  309
+            instance_count[klass] = 0
  310
+        transaction.commit()
  311
+    finally:
  312
+        transaction.leave_transaction_management()
311 313
 
312 314
     # Get a count of the number of objects created for each class
313 315
     for klass in instance_count:
314 316
         instance_count[klass] = klass.objects.count()
315  
-        
  317
+
316 318
     # Add the generic tagged objects to the object list
317 319
     objects.extend(Tag.objects.all())
318 320
 
@@ -322,11 +324,13 @@ def serializerTest(format, self):
322 324
     # Flush the database and recreate from the serialized data
323 325
     management.call_command('flush', verbosity=0, interactive=False)
324 326
     transaction.enter_transaction_management()
325  
-    transaction.managed(True)
326  
-    for obj in serializers.deserialize(format, serialized_data):
327  
-        obj.save()
328  
-    transaction.commit()
329  
-    transaction.leave_transaction_management()
  327
+    try:
  328
+        transaction.managed(True)
  329
+        for obj in serializers.deserialize(format, serialized_data):
  330
+            obj.save()
  331
+        transaction.commit()
  332
+    finally:
  333
+        transaction.leave_transaction_management()
330 334
 
331 335
     # Assert that the deserialized data is the same
332 336
     # as the original source

0 notes on commit ccab4b0

Please sign in to comment.
Something went wrong with that request. Please try again.