#21275 closed Bug (fixed)
Cannot use migrations if model field specifies validators
Reported by: | Tim Graham | Owned by: | |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | loic@… | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
My assumption is that we shouldn't try to serialize the validators
attribute.
Traceback:
File "/home/tim/.virtualenvs/foo/local/lib/python2.7/site-packages/django/db/migrations/writer.py", line 185, in serialize raise ValueError("Cannot serialize: %r" % value) ValueError: Cannot serialize: <django.core.validators.RegexValidator object at 0x1bacc10>
Change History (9)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Cc: | added |
---|---|
Has patch: | set |
Needs tests: | set |
comment:4 by , 11 years ago
Needs tests: | unset |
---|
PR https://github.com/django/django/pull/1783.
Note that this will be needed if/when #21295 is merged.
comment:5 by , 11 years ago
Owner: | set to |
---|---|
Resolution: | → fixed |
Status: | new → closed |
comment:6 by , 11 years ago
Shouldn't this also be added to the release notes? If anyone has their own model with a custom RegexValidator where they currently pass a compiled regex, they'll need to pass a string now, or they will also hit this issue, right?
comment:7 by , 11 years ago
Please note that there is #22255, which is about adding a new flags
kwarg.
comment:8 by , 11 years ago
I've included this in the release notes with https://github.com/django/django/commit/4d0c5f61427a8e67552ee2d777fffbadc7aff3b2
After discussion with loic84 in #django-developers, it appears that validators should be serializable and that this error is due to the regex used by the username field of
contrib.auth.models.AbstractUser
not being serializable. Loic says validators may be useful for data migrations, hence a possible reason not to exclude them entirely.