Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#23639 closed Bug (fixed)

Doc error in RegexValidator.regex

Reported by: Claude Paroz Owned by: doriczapari
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

In https://docs.djangoproject.com/fr/1.7/ref/validators/#django.core.validators.RegexValidator.regex, I think that the effects of inverse_match are reversed. A ValidationError is raised when inverse_match=True and a match is found. Can someone confirm? Boolean logic, we love you!

Change History (6)

comment:1 Changed 8 years ago by Baptiste Mispelon

Easy pickings: set
Triage Stage: UnreviewedAccepted

Hi,

You're right (and I also find this sentence really hard to parse, but maybe that's just me):

>>> RegexValidator(regex='[a-z]')('1')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/tisba/Programming/testbed/boogz/django/core/validators.py", line 51, in __call__
    raise ValidationError(self.message, code=self.code)
django.core.exceptions.ValidationError: ['Enter a valid value.']
>>> RegexValidator(regex='[a-z]', inverse_match=True)('1')

I wouldn't be opposed to a rewrite of this paragraph since I find it quite confusing.

comment:2 Changed 8 years ago by Claude Paroz

Suggested patch:

  • docs/ref/validators.txt

    diff --git a/docs/ref/validators.txt b/docs/ref/validators.txt
    index 260c066..0b66dd2 100644
    a b to, or in lieu of custom ``field.clean()`` methods. 
    8181    .. attribute:: regex
    8282
    8383        The regular expression pattern to search for the provided ``value``,
    84         or a pre-compiled regular expression. Raises a
     84        or a pre-compiled regular expression. By default, raises a
    8585        :exc:`~django.core.exceptions.ValidationError` with :attr:`message`
    86         and :attr:`code` if :attr:`inverse_match` is ``False`` and a match is
    87         found, or if :attr:`inverse_match` is ``True`` and a match is not found.
    88         By default, matches any string (including an empty string).
     86        and :attr:`code` if a match is not found. That standard behavior might
     87        be reversed by setting :attr:`inverse_match` to ``True``, meaning that
     88        the :exc:`~django.core.exceptions.ValidationError` is raised when a
     89        match **is** found. By default, matches any string (including an empty
     90        string).
    8991
    9092    .. attribute:: message

comment:3 Changed 8 years ago by doriczapari

Owner: changed from nobody to doriczapari
Status: newassigned

comment:4 Changed 8 years ago by doriczapari

Has patch: set

comment:5 Changed 8 years ago by Baptiste Mispelon <bmispelon@…>

Resolution: fixed
Status: assignedclosed

In c48a29a02a457cfdb1cff11009401459ba24e870:

Fixed #23639 -- Fixed doc error in RegexValidator.regex

Thanks to @claudep for the report and the original patch.

comment:6 Changed 8 years ago by Baptiste Mispelon <bmispelon@…>

In d2a2af67f7c2c41a831acd33cd8cba5875c216cf:

[1.7.x] Fixed #23639 -- Fixed doc error in RegexValidator.regex

Thanks to @claudep for the report and the original patch.

Backport of c48a29a02a457cfdb1cff11009401459ba24e870 from master.

Note: See TracTickets for help on using tickets.
Back to Top