Projet

Général

Profil

0006-misc-do-not-log-condition-errors-61292.patch

Frédéric Péters, 01 février 2022 16:28

Télécharger (3,4 ko)

Voir les différences:

Subject: [PATCH 6/8] misc: do not log condition errors (#61292)

 wcs/backoffice/management.py | 1 -
 wcs/conditions.py            | 8 ++------
 wcs/fields.py                | 1 -
 wcs/workflows.py             | 6 ++----
 4 files changed, 4 insertions(+), 12 deletions(-)
wcs/backoffice/management.py
3111 3111
            if test_mode in ('django-condition', 'python-condition'):
3112 3112
                condition = Condition(
3113 3113
                    {'value': form.get_widget(test_mode).parse(), 'type': test_mode.split('-')[0]},
3114
                    log_errors=False,
3115 3114
                    record_errors=False,
3116 3115
                )
3117 3116
                try:
wcs/conditions.py
19 19
from django.utils.encoding import force_text
20 20
from quixote import get_publisher
21 21

  
22
from .qommon import _, force_str, get_logger
22
from .qommon import _, force_str
23 23

  
24 24

  
25 25
class ValidationError(ValueError):
......
28 28

  
29 29
class Condition:
30 30
    record_errors = True
31
    log_errors = False
32 31

  
33
    def __init__(self, condition, context=None, record_errors=True, log_errors=False):
32
    def __init__(self, condition, context=None, record_errors=True):
34 33
        if not condition:
35 34
            condition = {}
36 35
        self.type = condition.get('type')
37 36
        self.value = condition.get('value')
38 37
        self.context = context or {}
39
        self.log_errors = log_errors
40 38
        self.record_errors = record_errors
41 39

  
42 40
    def __repr__(self):
......
55 53
        try:
56 54
            return self.unsafe_evaluate()
57 55
        except Exception as e:
58
            if self.log_errors:
59
                get_logger().warning('failed to evaluate %r (%r)', self, e)
60 56
            if self.record_errors:
61 57
                summary = _('Failed to evaluate condition')
62 58
                get_publisher().record_error(
wcs/fields.py
2537 2537

  
2538 2538

  
2539 2539
class PageCondition(Condition):
2540
    log_errors = True
2541 2540
    record_errors = False
2542 2541

  
2543 2542
    def get_data(self):
wcs/workflows.py
2217 2217

  
2218 2218
        return False
2219 2219

  
2220
    def check_condition(self, formdata, record_errors=True, log_errors=False):
2220
    def check_condition(self, formdata, record_errors=True):
2221 2221
        context = {'formdata': formdata, 'status_item': self}
2222 2222
        try:
2223
            return Condition(
2224
                self.condition, context, record_errors=record_errors, log_errors=log_errors
2225
            ).evaluate()
2223
            return Condition(self.condition, context, record_errors=record_errors).evaluate()
2226 2224
        except RuntimeError:
2227 2225
            return False
2228 2226

  
2229
-