[Django] #22255: RegexValidator needs support for flags passed to `re.compile` (migrations do not allow for compiled patterns)

19 views
Skip to first unread message

Django

unread,
Mar 12, 2014, 11:31:27 AM3/12/14
to django-...@googlegroups.com
#22255: RegexValidator needs support for flags passed to `re.compile` (migrations
do not allow for compiled patterns)
------------------------------+--------------------
Reporter: blueyed | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------
When using a RegexValidator with a compiled pattern, `makemigration`
fails:

{{{
ValueError: Cannot serialize: <_sre.SRE_Pattern object at 0x24e8ac0>
}}}

A sample model:
{{{
from django.core.validators import RegexValidator
pattern = re.compile(r'foo', re.IGNORECASE)
validator = RegexValidator(pattern)

class Model(models.Model):
foo = models.CharField(
validators = [validator],
...
)
}}}

This is somehow expected, and when passing in the pattern uncompiled it
works.
But this won't allow to use re.IGNORE_CASE or other flags for `re.compile`
anymore.

RegexValidator should support a new argument `flags`, which would then be
used for non-compiled patterns (passed on to `re.compile`).
(https://github.com/django/django/blob/master/django/core/validators.py#L25)

Let me know, if I could provide a pull request / patch for this (as far as
I can see) trivial change.

(It seems like with the new migrations, supporting a pre-compiled pattern
is not really relevant anymore (but could be kept still))

(I found this related commit:
https://github.com/django/django/commit/e565e1332ddfbb44fe7e6139375e3c243af7398d)

--
Ticket URL: <https://code.djangoproject.com/ticket/22255>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 12, 2014, 11:42:17 AM3/12/14
to django-...@googlegroups.com
#22255: RegexValidator needs support for flags passed to `re.compile` (migrations
do not allow for compiled patterns)
------------------------------+--------------------------------------

Reporter: blueyed | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by blueyed):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Since you can pass the flag(s) using `(?i)` etc, this can be easily worked
around.

--
Ticket URL: <https://code.djangoproject.com/ticket/22255#comment:1>

Django

unread,
Mar 12, 2014, 11:49:46 AM3/12/14
to django-...@googlegroups.com
#22255: RegexValidator needs support for flags passed to `re.compile` (migrations
do not allow for compiled patterns)
--------------------------------------+------------------------------------
Reporter: blueyed | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by erikr):

* type: Bug => Cleanup/optimization
* easy: 0 => 1
* stage: Unreviewed => Accepted


Comment:

So, with the latest comment, are you suggesting you no longer think
patching this is useful?

Patching this makes sense to me: it can make code that uses RegexValidator
a lot clearer when flags are passed separately, and the change required in
Django is trivial.
For clarity: #21275 explains that the serialisation of validators is an
intentional feature.

--
Ticket URL: <https://code.djangoproject.com/ticket/22255#comment:2>

Django

unread,
Mar 13, 2014, 6:52:39 AM3/13/14
to django-...@googlegroups.com
#22255: RegexValidator needs support for flags passed to `re.compile` (migrations
do not allow for compiled patterns)
--------------------------------------+------------------------------------
Reporter: blueyed | Owner: dekomote
Type: Cleanup/optimization | Status: assigned

Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by dekomote):

* owner: nobody => dekomote
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/22255#comment:3>

Django

unread,
Mar 13, 2014, 7:29:31 AM3/13/14
to django-...@googlegroups.com
#22255: RegexValidator needs support for flags passed to `re.compile` (migrations
do not allow for compiled patterns)
--------------------------------------+------------------------------------
Reporter: blueyed | Owner: dekomote
Type: Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by dekomote):

* cc: dekomote (added)
* has_patch: 0 => 1


Comment:

Pull request here https://github.com/django/django/pull/2427

--
Ticket URL: <https://code.djangoproject.com/ticket/22255#comment:4>

Django

unread,
Mar 13, 2014, 9:30:18 AM3/13/14
to django-...@googlegroups.com
#22255: RegexValidator needs support for flags passed to `re.compile` (migrations
do not allow for compiled patterns)
--------------------------------------+------------------------------------
Reporter: blueyed | Owner: dekomote
Type: Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by dekomote):

Updated the patch https://github.com/django/django/pull/2427

--
Ticket URL: <https://code.djangoproject.com/ticket/22255#comment:5>

Django

unread,
Mar 19, 2014, 2:49:25 AM3/19/14
to django-...@googlegroups.com
#22255: RegexValidator needs support for flags passed to `re.compile` (migrations
do not allow for compiled patterns)
-------------------------------------+-------------------------------------
Reporter: blueyed | Owner: dekomote
Type: Bug | Status: assigned

Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 1 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by blueyed):

* type: Cleanup/optimization => Bug
* stage: Accepted => Ready for checkin


Comment:

FWIW, the patch looks good to me.

Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/22255#comment:6>

Django

unread,
Mar 19, 2014, 2:49:57 AM3/19/14
to django-...@googlegroups.com
#22255: RegexValidator needs support for flags passed to `re.compile` (migrations
do not allow for compiled patterns)
-------------------------------------+-------------------------------------
Reporter: blueyed | Owner: dekomote
Type: | Status: assigned
Cleanup/optimization | Version: master
Component: Core (Other) | Resolution:
Severity: Normal | Triage Stage: Ready for
Keywords: | checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by blueyed):

* type: Bug => Cleanup/optimization


--
Ticket URL: <https://code.djangoproject.com/ticket/22255#comment:7>

Django

unread,
Mar 19, 2014, 3:54:09 AM3/19/14
to django-...@googlegroups.com
#22255: RegexValidator needs support for flags passed to `re.compile` (migrations
do not allow for compiled patterns)
-------------------------------------+-------------------------------------
Reporter: blueyed | Owner: dekomote
Type: | Status: assigned
Cleanup/optimization | Version: master
Component: Core (Other) | Resolution:
Severity: Normal | Triage Stage: Ready for
Keywords: | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by erikr):

* needs_better_patch: 0 => 1


Comment:

Left a comment on the patch. Minor issue in the docs.

--
Ticket URL: <https://code.djangoproject.com/ticket/22255#comment:8>

Django

unread,
Mar 21, 2014, 6:15:13 AM3/21/14
to django-...@googlegroups.com
#22255: RegexValidator needs support for flags passed to `re.compile` (migrations
do not allow for compiled patterns)
-------------------------------------+-------------------------------------
Reporter: blueyed | Owner: dekomote
Type: | Status: closed
Cleanup/optimization | Version: master
Component: Core (Other) | Resolution: fixed

Severity: Normal | Triage Stage: Ready for
Keywords: | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Erik Romijn <erik@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"4d0c5f61427a8e67552ee2d777fffbadc7aff3b2"]:
{{{
#!CommitTicketReference repository=""
revision="4d0c5f61427a8e67552ee2d777fffbadc7aff3b2"
Fixed #22255 -- Added support for specifying re flags in RegexValidator
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22255#comment:9>

Django

unread,
Mar 21, 2014, 6:34:48 AM3/21/14
to django-...@googlegroups.com
#22255: RegexValidator needs support for flags passed to `re.compile` (migrations
do not allow for compiled patterns)
-------------------------------------+-------------------------------------
Reporter: blueyed | Owner: dekomote
Type: | Status: closed
Cleanup/optimization | Version: master
Component: Core (Other) | Resolution: fixed
Severity: Normal | Triage Stage: Ready for
Keywords: | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by erikr):

* needs_better_patch: 1 => 0


Comment:

This was also backported to 1.7, thanks for the patch :)

--
Ticket URL: <https://code.djangoproject.com/ticket/22255#comment:10>

Reply all
Reply to author
Forward
0 new messages