Projet

Général

Profil

0001-misc-report-instead-of-recording-errors-when-using-i.patch

Frédéric Péters, 20 novembre 2022 12:27

Télécharger (2,87 ko)

Voir les différences:

Subject: [PATCH] misc: report instead of recording errors, when using inspect
 tools (#57553)

 tests/backoffice_pages/test_form_inspect.py | 8 ++++++++
 wcs/publisher.py                            | 5 +++++
 wcs/qommon/errors.py                        | 6 ++++++
 3 files changed, 19 insertions(+)
tests/backoffice_pages/test_form_inspect.py
347 347
    assert 'syntax error' in resp.text
348 348
    assert 'Invalid block tag' in resp.text
349 349

  
350
    # check errors are not logged, and are nicely reported
351
    pub.loggederror_class.wipe()
352
    resp.form['test_mode'] = 'django-condition'
353
    resp.form['django-condition'] = 'form_objects|filter_by:"not a field"|filter_value:"test"'
354
    resp = resp.form.submit()
355
    assert resp.pyquery('#test-tool-result p:last-child').text() == 'Invalid filter "not a field"'
356
    assert pub.loggederror_class.count() == 0
357

  
350 358

  
351 359
def test_inspect_page_with_related_objects(pub):
352 360
    user = create_user(pub, is_admin=True)
wcs/publisher.py
32 32
from .admin import RootDirectory as AdminRootDirectory
33 33
from .backoffice import RootDirectory as BackofficeRootDirectory
34 34
from .Defaults import *  # noqa pylint: disable=wildcard-import
35
from .qommon import errors
35 36
from .qommon.cron import CronJob
36 37
from .qommon.publisher import QommonPublisher, get_request, set_publisher_class
37 38
from .qommon.tokens import Token
......
421 422
        if error_summary is None:
422 423
            return
423 424

  
425
        if get_request() and getattr(get_request(), 'inspect_mode', False):
426
            # do not record anything when trying random things in the inspector
427
            raise errors.InspectException(error_summary)
428

  
424 429
        error_summary = str(error_summary).replace('\n', ' ')[:400].strip()
425 430

  
426 431
        logged_exception = None
wcs/qommon/errors.py
134 134
    pass
135 135

  
136 136

  
137
class InspectException(Exception):
138
    # exception raised in place of logged errors when using the inspect tools
139
    def get_error_message(self):
140
        return str(self)
141

  
142

  
137 143
TraversalError.title = _('Page not found')
138 144
TraversalError.description = _(
139 145
    "The requested link does not exist on this site.  If "
140
-