#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107017fd816beb8-5f506dde-1133-44ef-aab9-1940e4b3c25a-000000%40eu-central-1.amazonses.com.

Reply via email to