Skip to content

Instantly share code, notes, and snippets.

@dpetzel
Created June 22, 2012 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpetzel/2974494 to your computer and use it in GitHub Desktop.
Save dpetzel/2974494 to your computer and use it in GitHub Desktop.
def _commit_change(self, safe=False):
"""
A wrapper around transaction.commit so we can catch, log, retry
@type safe: Boolean
@param safe: Indicates if a safe commit is required.
Sometimes its OK if the commit fails. When set to false,
will raise an exception, instead of just logging it
@rtype: Boolean
@return: Boolean indicating result of commit attempt
"""
res = True
try:
commit()
except ConflictError as e:
log.warn("Conflict Detecting when trying to commit. Going to sync and retry")
conn.syncdb()
try:
commit()
except ConflictError as e2:
#It ain't good, but we should push forward and try and finish the rules
log.error("Commit failed again with conflict. Moving onto next item", e2)
if safe == False:
res = False
else:
raise
#Sync for good measure
conn.syncdb()
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment