@@ -390,7 +390,9 @@ def tearDownClass(cls):
390390 cls ._teardown_registry (cls )
391391 super ().tearDownClass ()
392392
393- def _test_exception (self , test_type , wrapping_exc , exc_name , severity ):
393+ def _test_exception (
394+ self , test_type , wrapping_exc , exc_name , severity , will_be_retried = True
395+ ):
394396 log_model = self .env ["rest.log" ].sudo ()
395397 initial_entries = log_model .search ([])
396398 # Context: we are running in a transaction case which uses savepoints.
@@ -400,7 +402,9 @@ def _test_exception(self, test_type, wrapping_exc, exc_name, severity):
400402 # Init fake collection w/ new env
401403 collection = _PseudoCollection (self ._collection_name , new_env )
402404 service = self ._get_service (self , collection = collection )
403- with self ._get_mocked_request (env = new_env ):
405+ with self ._get_mocked_request (env = new_env ), mock .patch .object (
406+ service , "_is_request_will_be_retried" , return_value = will_be_retried
407+ ):
404408 try :
405409 service .dispatch ("fail" , test_type )
406410 except Exception as err :
@@ -413,15 +417,20 @@ def _test_exception(self, test_type, wrapping_exc, exc_name, severity):
413417 with new_rollbacked_env () as new_env :
414418 log_model = new_env ["rest.log" ].sudo ()
415419 entry = log_model .search ([]) - initial_entries
416- expected = {
417- "collection" : service ._collection ,
418- "state" : "failed" ,
419- "result" : "null" ,
420- "exception_name" : exc_name ,
421- "exception_message" : "Failed as you wanted!" ,
422- "severity" : severity ,
423- }
424- self .assertRecordValues (entry , [expected ])
420+ if will_be_retried :
421+ # retryable error must bubble up to the retrying mechanism
422+ self .assertEqual (len (entry ), 0 )
423+ else :
424+ # not retryable, so we log it
425+ expected = {
426+ "collection" : service ._collection ,
427+ "state" : "failed" ,
428+ "result" : "null" ,
429+ "exception_name" : exc_name ,
430+ "exception_message" : "Failed as you wanted!" ,
431+ "severity" : severity ,
432+ }
433+ self .assertRecordValues (entry , [expected ])
425434
426435 @staticmethod
427436 def _get_test_controller (class_or_instance , root_path = None ):
@@ -436,4 +445,12 @@ def test_log_exception_retryable(self):
436445 FakeConcurrentUpdateError ,
437446 "odoo.addons.rest_log.tests.common.FakeConcurrentUpdateError" ,
438447 "warning" ,
448+ will_be_retried = True ,
449+ )
450+ self ._test_exception (
451+ "retryable" ,
452+ FakeConcurrentUpdateError ,
453+ "odoo.addons.rest_log.tests.common.FakeConcurrentUpdateError" ,
454+ "warning" ,
455+ will_be_retried = False ,
439456 )
0 commit comments