logged_errors: store last occurence error context (#25086)

This commit is contained in:
Thomas NOËL 2021-07-26 14:11:42 +02:00
parent e6eead49b4
commit 8dba0f79db
3 changed files with 22 additions and 3 deletions

View File

@ -6321,6 +6321,10 @@ def test_logged_errors(pub):
resp = resp.form.submit('submit')
assert pub.loggederror_class.count() == 1
# new expression, but raise the same exception (ZeroDivisionError),
# just update the created logged error
jump.condition = {'type': 'python', 'value': '2//0'}
workflow.store()
resp = app.get('/test/')
resp = resp.form.submit('submit').follow()
resp = resp.form.submit('submit')
@ -6333,6 +6337,7 @@ def test_logged_errors(pub):
)
)[0]
assert error.occurences_count == 2
assert error.expression == '2//0'
assert len(list(pub.loggederror_class.get_with_indexed_value('formdef_id', '34'))) == 1
assert len(list(pub.loggederror_class.get_with_indexed_value('formdef_id', 'X'))) == 0

View File

@ -94,6 +94,22 @@ class LoggedError:
error.store()
return error
def record_new_occurence(self, error):
if not self.id:
return
self.occurences_count += 1
self.latest_occurence_timestamp = now()
# update with new error context
self.formdata_id = error.formdata_id
self.summary = error.summary
self.traceback = error.traceback
self.expression = error.expression
self.expression_type = error.expression_type
# exception should be the same (same tech_id), record just in case
self.exception_class = error.exception_class
self.exception_message = error.exception_message
self.store()
@classmethod
def record_error(cls, error_summary, plain_error_msg, publisher, *args, **kwargs):
formdef = kwargs.pop('formdef', None)

View File

@ -3077,9 +3077,7 @@ class LoggedError(SqlMixin, wcs.logged_errors.LoggedError):
existing_errors = list(self.get_with_indexed_value('tech_id', self.tech_id))
if existing_errors:
error = existing_errors[0]
error.occurences_count += 1
error.latest_occurence_timestamp = self.latest_occurence_timestamp
return error.store()
error.record_new_occurence(self)
else:
column_names = sql_dict.keys()
sql_statement = '''UPDATE %s SET %s WHERE id = %%(id)s RETURNING id''' % (