feature: Add trace information to SQL statement

remotes/origin/3.4.0rc
Miguel Gonzalez 2018-04-18 13:06:57 +02:00 committed by Álex Hermida
parent ee862b0748
commit 6faed218ba
1 changed files with 6 additions and 1 deletions

View File

@ -151,9 +151,14 @@ def update_attr_in_bulk_for_ids(values, attr, model):
# We can have deadlocks with multiple updates over the same object # We can have deadlocks with multiple updates over the same object
# In that situation we just retry # In that situation we just retry
import time
ts = time.time()
def trace_info(retries):
return '/* query=update_attr_in_bulk id={ts} retries={retries} */'.format(retries=retries, ts=ts)
def _run_sql(retries=0, max_retries=3): def _run_sql(retries=0, max_retries=3):
try: try:
cursor.execute(sql) cursor.execute(trace_info(retries) + sql)
except DatabaseError: except DatabaseError:
if retries < max_retries: if retries < max_retries:
_run_sql(retries + 1) _run_sql(retries + 1)