File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -280,10 +280,19 @@ def transact_reraise(exc_class, exceptions):
280
280
def commit ():
281
281
caches = _get_caches ()
282
282
if not caches : return
283
+
284
+ try :
285
+ for cache in caches :
286
+ cache .flush ()
287
+ except :
288
+ rollback ()
289
+ raise
290
+
283
291
primary_cache = caches [0 ]
284
292
other_caches = caches [1 :]
285
293
exceptions = []
286
- try : primary_cache .commit ()
294
+ try :
295
+ primary_cache .commit ()
287
296
except :
288
297
exceptions .append (sys .exc_info ())
289
298
for cache in other_caches :
Original file line number Diff line number Diff line change @@ -296,6 +296,34 @@ def test():
296
296
pass
297
297
test ()
298
298
299
+ @raises_exception (ZeroDivisionError )
300
+ def test_db_session_exceptions_1 (self ):
301
+ def before_insert (self ):
302
+ 1 / 0
303
+ self .X .before_insert = before_insert
304
+ with db_session :
305
+ self .X (a = 3 , b = 3 )
306
+ # Should raise ZeroDivisionError and not CommitException
307
+
308
+ @raises_exception (ZeroDivisionError )
309
+ def test_db_session_exceptions_2 (self ):
310
+ def before_insert (self ):
311
+ 1 / 0
312
+ self .X .before_insert = before_insert
313
+ with db_session :
314
+ self .X (a = 3 , b = 3 )
315
+ commit ()
316
+ # Should raise ZeroDivisionError and not CommitException
317
+
318
+ @raises_exception (ZeroDivisionError )
319
+ def test_db_session_exceptions_3 (self ):
320
+ def before_insert (self ):
321
+ 1 / 0
322
+ self .X .before_insert = before_insert
323
+ with db_session :
324
+ self .X (a = 3 , b = 3 )
325
+ db .commit ()
326
+ # Should raise ZeroDivisionError and not CommitException
299
327
300
328
db = Database ('sqlite' , ':memory:' )
301
329
You can’t perform that action at this time.
0 commit comments