Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#13341 closed (fixed)

RegexValidator documentation minor problems

Reported by: Simon Meers Owned by: David Fischer
Component: Documentation Version: master
Severity: Keywords: validators, regexvalidator
Cc: djfische@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In 'RegexValidator' section of documentation (http://code.djangoproject.com/browser/django/trunk/docs/ref/validators.txt#L59) there seem to be several minor problems:

  • Default value stated as None in method signature, but 'invalid' in details
  • Order of parameters in details differs to method signature (confusing)
  • Insufficient explanation of the purpose of the code parameter

Attachments (2)

13341-regexvalidator.diff (1.2 KB) - added by David Fischer 6 years ago.
Improved RegexValidator documentation
13341-update.diff (736 bytes) - added by David Fischer 6 years ago.
Clarification update regarding the first parameter "regex"

Download all attachments as: .zip

Change History (10)

comment:1 Changed 6 years ago by Russell Keith-Magee

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

comment:2 Changed 6 years ago by Simon Meers

milestone: 1.31.2

Oops, marked wrong milestone initially. This really shouldn't hang around.

Changed 6 years ago by David Fischer

Attachment: 13341-regexvalidator.diff added

Improved RegexValidator documentation

comment:3 Changed 6 years ago by David Fischer

Cc: djfische@… added
Has patch: set
Owner: changed from nobody to David Fischer
Status: newassigned

I added a patch that addresses the three points made by the ticket originator. In general, however, the validator documentation could use a little love. I think another ticket may be in order.

comment:4 Changed 6 years ago by Alex Gaynor

Triage Stage: AcceptedReady for checkin

comment:5 Changed 6 years ago by Russell Keith-Magee

Resolution: fixed
Status: assignedclosed

(In [13148]) Fixed #13341 -- Clarified the arguments to RegexValidators. Thanks to DrMeers for the report, and David Fischer for the draft text.

Changed 6 years ago by David Fischer

Attachment: 13341-update.diff added

Clarification update regarding the first parameter "regex"

comment:6 Changed 6 years ago by David Fischer

Resolution: fixed
Status: closedreopened

While the original patch was being cleaned up and committed, there was a slight change to try to rectify the documentation with what the actual source code says. The first patch changed the documentation such that it appeared that the first parameter of RegexValidator -- the regex pattern regex -- is required. The code says that it is optional. While it is technically an optional parameter, a TypeError is thrown if it is not provided (see traceback). The documentation should be updated such that users don't try to use the defaults. They should always provide the regex parameter. The update patch makes it clear that regex is required. I don't like the idea of having the docs technically out of sync with the code, but I think it is the best option in this instance.

I opened ticket #13511 regarding changing the regex parameter to required.

>>> from django.core.validators import RegexValidator
>>> RegexValidator()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/private/tmp/testarea/lib/python2.6/site-packages/django/core/validators.py", line 32, in __init__
    self.regex = re.compile(regex)
  File "/private/tmp/testarea/lib/python2.6/re.py", line 190, in compile
    return _compile(pattern, flags)
  File "/private/tmp/testarea/lib/python2.6/re.py", line 241, in _compile
    raise TypeError, "first argument must be string or compiled pattern"
TypeError: first argument must be string or compiled pattern

comment:7 Changed 6 years ago by Russell Keith-Magee

Resolution: fixed
Status: reopenedclosed

(In [13201]) Fixed #13341 -- Clarified default arguments to the RegexValidator. Thanks to David Fischer for the report and patch.

comment:8 Changed 5 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

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