Opened 4 years ago
Closed 4 years ago
#33605 closed Bug (fixed)
Use of RegexValidator can cause migration generation to raise AttributeError
| Reported by: | Brian Helba | Owned by: | Brian Helba |
|---|---|---|---|
| Component: | Migrations | Version: | 4.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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
Change History (4)
comment:1 by , 4 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:2 by , 4 years ago
| Needs tests: | set |
|---|---|
| Patch needs improvement: | set |
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Bug |
comment:3 by , 4 years ago
| Needs tests: | unset |
|---|---|
| Patch needs improvement: | unset |
| Triage Stage: | Accepted → Ready for checkin |
Thanks for the report.
PR