logged errors: fix integrity error on tech_id (#53839)

This commit is contained in:
Lauréline Guérin 2021-05-11 11:29:26 +02:00
parent ee403b7840
commit 203be870d5
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 12 additions and 4 deletions

View File

@ -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()

View File

@ -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()