logged errors: fix integrity error on tech_id (#53839)
This commit is contained in:
parent
ee403b7840
commit
203be870d5
|
@ -87,9 +87,6 @@ class LoggedError:
|
|||
|
||||
error.first_occurence_timestamp = now()
|
||||
error.tech_id = error.build_tech_id()
|
||||
existing_errors = list(cls.get_with_indexed_value('tech_id', error.tech_id))
|
||||
if existing_errors:
|
||||
error = existing_errors[0]
|
||||
error.occurences_count += 1
|
||||
error.latest_occurence_timestamp = now()
|
||||
error.store()
|
||||
|
|
13
wcs/sql.py
13
wcs/sql.py
|
@ -3005,7 +3005,18 @@ class LoggedError(SqlMixin, wcs.logged_errors.LoggedError):
|
|||
', '.join(column_names),
|
||||
', '.join(['%%(%s)s' % x for x in column_names]),
|
||||
)
|
||||
cur.execute(sql_statement, sql_dict)
|
||||
try:
|
||||
cur.execute(sql_statement, sql_dict)
|
||||
except psycopg2.IntegrityError:
|
||||
# tech_id already used ?
|
||||
conn.rollback()
|
||||
existing_errors = list(self.get_with_indexed_value('tech_id', self.tech_id))
|
||||
if not existing_errors:
|
||||
raise
|
||||
error = existing_errors[0]
|
||||
error.occurences_count += 1
|
||||
error.latest_occurence_timestamp = self.latest_occurence_timestamp
|
||||
return error.store()
|
||||
self.id = cur.fetchone()[0]
|
||||
else:
|
||||
column_names = sql_dict.keys()
|
||||
|
|
Loading…
Reference in New Issue