[Django] #33605: Use of RegexValidator can cause migration generation to raise AttributeError

34 views
Skip to first unread message

Django

unread,
Mar 29, 2022, 7:50:46 PM3/29/22
to django-...@googlegroups.com
#33605: Use of RegexValidator can cause migration generation to raise
AttributeError
-----------------------------------------+------------------------
Reporter: Brian Helba | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
If a model:
{{{
my_field = CharField(
max_length=64,
validators=[RegexValidator('pattern')],
)
}}}

is migrated to:
{{{
my_field = CharField(
max_length=64,
validators=[RegexValidator(re.compile('pattern'))],
)
}}}

an uncaught `AttributeError: 'str' object has no attribute 'pattern'` will
be raised from here:
https://github.com/django/django/blob/59ab3fd0e9e606d7f0f7ca26609c06ee679ece97/django/db/migrations/utils.py#L18
,
caused by this comparison:
https://github.com/django/django/blob/59ab3fd0e9e606d7f0f7ca26609c06ee679ece97/django/db/migrations/autodetector.py#L1143

This is because comparing a `RegexObject` (the wrapper for a compiled
regex) to a string is not properly handled. This issue was introduced by
https://github.com/django/django/commit/91f701f4fc324cd2feb7dbf151338a358ca0ea18

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

Django

unread,
Mar 29, 2022, 7:51:04 PM3/29/22
to django-...@googlegroups.com
#33605: Use of RegexValidator can cause migration generation to raise
AttributeError
-------------------------------+---------------------------------------
Reporter: Brian Helba | Owner: Brian Helba
Type: Uncategorized | Status: assigned
Component: Migrations | Version: 4.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------
Changes (by Brian Helba):

* owner: nobody => Brian Helba
* status: new => assigned


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

Django

unread,
Mar 30, 2022, 1:46:12 AM3/30/22
to django-...@googlegroups.com
#33605: Use of RegexValidator can cause migration generation to raise
AttributeError
-----------------------------+---------------------------------------
Reporter: Brian Helba | Owner: Brian Helba
Type: Bug | Status: assigned

Component: Migrations | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1
* type: Uncategorized => Bug
* needs_tests: 0 => 1
* stage: Unreviewed => Accepted


Comment:

Thanks for the report.

[https://github.com/django/django/pull/15555 PR]

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

Django

unread,
Apr 4, 2022, 1:38:54 AM4/4/22
to django-...@googlegroups.com
#33605: Use of RegexValidator can cause migration generation to raise
AttributeError
-----------------------------+---------------------------------------------

Reporter: Brian Helba | Owner: Brian Helba
Type: Bug | Status: assigned
Component: Migrations | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin

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

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin


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

Django

unread,
Apr 4, 2022, 2:27:09 AM4/4/22
to django-...@googlegroups.com
#33605: Use of RegexValidator can cause migration generation to raise
AttributeError
-----------------------------+---------------------------------------------
Reporter: Brian Helba | Owner: Brian Helba
Type: Bug | Status: closed
Component: Migrations | Version: 4.0
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"2d5215c675c2f128f7e9fc296cd5a0a5a527dff4" 2d5215c]:
{{{
#!CommitTicketReference repository=""
revision="2d5215c675c2f128f7e9fc296cd5a0a5a527dff4"
Fixed #33605 -- Fixed migration crash when altering RegexValidator to pre-
compiled regular expression.
}}}

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

Reply all
Reply to author
Forward
0 new messages