Code

Opened 6 months ago

Closed 6 months ago

Last modified 4 weeks ago

#21275 closed Bug (fixed)

Cannot use migrations if model field specifies validators

Reported by: timo Owned by: Tim Graham <timograham@…>
Component: Migrations Version: master
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>

Attachments (0)

Change History (8)

comment:1 Changed 6 months ago by timo

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.

comment:2 Changed 6 months ago by loic84

  • Cc loic@… added
  • Has patch set
  • Needs tests set

comment:3 Changed 6 months ago by loic84

Another POC around the concept of a deconstructible decorator.

https://github.com/loic/django/tree/ticket21275_take2.

comment:4 Changed 6 months ago by loic84

  • Needs tests unset

PR https://github.com/django/django/pull/1783.

Note that this will be needed if/when #21295 is merged.

comment:5 Changed 6 months ago by Tim Graham <timograham@…>

  • Owner set to Tim Graham <timograham@…>
  • Resolution set to fixed
  • Status changed from new to closed

In e565e1332ddfbb44fe7e6139375e3c243af7398d:

Fixed #21275 -- Fixed a serializer error when generating migrations for contrib.auth.

The migration serializer now looks for a deconstruct method on any object.

comment:6 Changed 4 weeks ago by erikr

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 Changed 4 weeks ago by blueyed

Please note that there is #22255, which is about adding a new flags kwarg.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.