Projet

Général

Profil

Bug #55014

validation regex sur valeur à None

Ajouté par Frédéric Péters il y a presque 3 ans. Mis à jour il y a presque 3 ans.

Statut:
Fermé
Priorité:
Normal
Assigné à:
Version cible:
-
Début:
21 juin 2021
Echéance:
% réalisé:

0%

Temps estimé:
Patch proposed:
Oui
Planning:
Non

Description

Exception:
  type = '<class 'TypeError'>', value = 'expected string or bytes-like object'

Stack trace (most recent call first):
  File "/usr/lib/python3.7/re.py", line 173, in match
   171     """Try to apply the pattern at the start of the string, returning
   172     a Match object, or None if no match was found.""" 
>  173     return _compile(pattern, flags).match(string)
   174
   175 def fullmatch(pattern, string, flags=0):

  locals:
     flags = 0
     pattern = '^(?:\\d+)$'
     string = None

  File "/usr/lib/python3/dist-packages/wcs/qommon/form.py", line 1201, in regex_validation
  1199
  1200             def regex_validation(value):
> 1201                 return bool(re.match(r'^(?:%s)$' % pattern, value))
  1202
  1203             return regex_validation

  locals:
     pattern = '\\d+'
     value = None

  File "/usr/lib/python3/dist-packages/wcs/qommon/form.py", line 1274, in _parse
  1272             )
  1273
> 1274         if self.validation_function and not self.validation_function(self.value):
  1275             self.error = self.validation_function_error_message or _('invalid value')
  1276

  locals:
     request = <wcs.compat.CompatHTTPRequest object at 0x7f62f8514dd8>
     self = <WcsExtraStringWidget at 7f62f3abfe48: f102>

  File "/usr/lib/python3/dist-packages/quixote/form/widget.py", line 137, in parse
   135                     self._parse(request)
   136                 except WidgetValueError as exc:
>  137                     self.set_error(stringify(exc))
   138                 if (self.required and self.value is None and
   139                     not self.has_error()):

  locals:
     request = <wcs.compat.CompatHTTPRequest object at 0x7f62f8514dd8>
     self = <WcsExtraStringWidget at 7f62f3abfe48: f102>
     submitted = True

Je décide de ne pas chercher la situation précise.


Fichiers


Demandes liées

Dupliqué par w.c.s. - Bug #48551: sur validation regex TypeError: expected string or bytes-like objectFermé14 novembre 2020

Actions

Révisions associées

Révision 7b25253c (diff)
Ajouté par Frédéric Péters il y a presque 3 ans

forms: do not call validation function on empty values (#55014)

Historique

#1

Mis à jour par Frédéric Péters il y a presque 3 ans

Ça adopte le même comportement qu'ailleurs, où validation_function est uniquement appelé quand il y a une valeur, genre StringWidget :

    def _parse(self, request):
        QuixoteStringWidget._parse(self, request)
        if self.value:
            self.value = self.value.strip()
        if self.value and self.validation_function:
            try:
                self.validation_function(self.value)
            except ValueError as e:
                self.error = str(e)
#2

Mis à jour par Lauréline Guérin il y a presque 3 ans

  • Statut changé de Solution proposée à Solution validée
#3

Mis à jour par Frédéric Péters il y a presque 3 ans

  • Statut changé de Solution validée à Résolu (à déployer)
commit 7b25253cf9a720c6b1b1783565b9fee5902a8e73
Author: Frédéric Péters <fpeters@entrouvert.com>
Date:   Mon Jun 21 12:29:59 2021 +0200

    forms: do not call validation function on empty values (#55014)
#4

Mis à jour par Frédéric Péters il y a presque 3 ans

  • Statut changé de Résolu (à déployer) à Solution déployée
#5

Mis à jour par Frédéric Péters il y a plus de 2 ans

  • Dupliqué par Bug #48551: sur validation regex TypeError: expected string or bytes-like object ajouté

Formats disponibles : Atom PDF