Projet

Général

Profil

0001-logged_errors-store-last-occurence-error-context-250.patch

Thomas Noël, 26 juillet 2021 14:12

Télécharger (3,1 ko)

Voir les différences:

Subject: [PATCH] logged_errors: store last occurence error context (#25086)

 tests/form_pages/test_all.py |  5 +++++
 wcs/logged_errors.py         | 16 ++++++++++++++++
 wcs/sql.py                   |  4 +---
 3 files changed, 22 insertions(+), 3 deletions(-)
tests/form_pages/test_all.py
6321 6321
    resp = resp.form.submit('submit')
6322 6322
    assert pub.loggederror_class.count() == 1
6323 6323

  
6324
    # new expression, but raise the same exception (ZeroDivisionError),
6325
    # just update the created logged error
6326
    jump.condition = {'type': 'python', 'value': '2//0'}
6327
    workflow.store()
6324 6328
    resp = app.get('/test/')
6325 6329
    resp = resp.form.submit('submit').follow()
6326 6330
    resp = resp.form.submit('submit')
......
6333 6337
        )
6334 6338
    )[0]
6335 6339
    assert error.occurences_count == 2
6340
    assert error.expression == '2//0'
6336 6341

  
6337 6342
    assert len(list(pub.loggederror_class.get_with_indexed_value('formdef_id', '34'))) == 1
6338 6343
    assert len(list(pub.loggederror_class.get_with_indexed_value('formdef_id', 'X'))) == 0
wcs/logged_errors.py
93 93
        error.store()
94 94
        return error
95 95

  
96
    def record_new_occurence(self, error):
97
        if not self.id:
98
            return
99
        self.occurences_count += 1
100
        self.latest_occurence_timestamp = now()
101
        # update with new error context
102
        self.formdata_id = error.formdata_id
103
        self.summary = error.summary
104
        self.traceback = error.traceback
105
        self.expression = error.expression
106
        self.expression_type = error.expression_type
107
        # exception should be the same (same tech_id), record just in case
108
        self.exception_class = error.exception_class
109
        self.exception_message = error.exception_message
110
        self.store()
111

  
96 112
    @classmethod
97 113
    def record_error(cls, error_summary, plain_error_msg, publisher, *args, **kwargs):
98 114
        formdef = kwargs.pop('formdef', None)
wcs/sql.py
3060 3060
                    existing_errors = list(self.get_with_indexed_value('tech_id', self.tech_id))
3061 3061
            if existing_errors:
3062 3062
                error = existing_errors[0]
3063
                error.occurences_count += 1
3064
                error.latest_occurence_timestamp = self.latest_occurence_timestamp
3065
                return error.store()
3063
                error.record_new_occurence(self)
3066 3064
        else:
3067 3065
            column_names = sql_dict.keys()
3068 3066
            sql_statement = '''UPDATE %s SET %s WHERE id = %%(id)s RETURNING id''' % (
3069
-