Project

General

Profile

Bug #9141

Updated by Brett Smith almost 8 years ago

This is a common idiom in @events.py@: 

 <pre><code class="python">for tries_left in RetryLoop(...): 
     ... 
 if tries_left == 0: 
     _logger.exception("Everything is terrible") 
     ... 
 </code></pre> 

 There are two bugs in this pattern. 

 First, if the body of the RetryLoop succeeds on the last attempt, @tries_left == 0@ will be true, and it will be incorrectly treated as a failure. 

 Second, no exception is being handled at the time we call @_logger.exception()@.    Testing suggests that in this case, it just writes "None" where it would normally write a traceback.    That's not helping anybody, so we should call a different logging method. 

 Separately from that, there are two times when the body of the RetryLoop is: 

 <pre><code class="python">                      try: 
                         items = self.api.[some method].execute() 
                         break 
                     except errors.ApiError as error: 
                         pass 
                     else: 
                         tries_left = 0 
                         break 
 </code></pre> 

 @break@ immediately breaks the control flow, so the @else:@ block will never run.    Was that supposed to be @except Exception:@ instead?

Back