#27884: validators needs to be an iterable since Django 1.11 -------------------------------------+------------------------------------- Reporter: Thom | Owner: nobody Wiggers | Type: | Status: new Uncategorized | Component: Database | Version: 1.11 layer (models, ORM) | Severity: Normal | Keywords: validators Triage Stage: | Has patch: 0 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -------------------------------------+------------------------------------- At one time with Django <1.11 (probably 1.10) someone wrote the following code:
{{{ class Bla(Model): someint = IntegerField(validators=MinValueValidator(1990)) }}} While he should have used an iterable for validators, note that this worked fine, and Django generated a migration: {{{ operations = [ migrations.CreateModel(name="Bla", fields=[ # ... ('someint', models.IntegerField(validators=django.core.validators.MinValueValidator(1990))), ]), ] }}} However, if this migration is loaded by Django 1.11 when running `migrate` or `makemigrate` or whatever, it raises the following exception: {{{ File "/builds/X/Y/website/Z/migrations/0011_auto_20161005_2141.py", line 10, in <module> class Migration(migrations.Migration): File "/builds/X/Y/website/Z/migrations/0011_auto_20161005_2141.py", line 22, in Migration ('someint', models.IntegerField(validators=django.core.validators.MinValueValidator(1990))), File "/builds/X/Y/.tox/py34-django11/lib/python3.4/site- packages/django/db/models/fields/__init__.py", line 183, in __init__ self._validators = list(validators) # Store for deconstruction later TypeError: 'MinValueValidator' object is not iterable }}} While I understand taking out code that allows for this poor coding style, this will make migrating to Django 1.11 perhaps not trivial for everyone. Simply fixing it in the Model is not enough, this generates a new migration and doesn't yet get rid of the old migration. I think the best way to work around this is to squash the offending migrations before moving to 1.11. My suggestion is noting this (or a better workaround/fix) in the release notes. -- Ticket URL: <https://code.djangoproject.com/ticket/27884> 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/054.40eb11df0883be1b5d2ff6bcad0b4f91%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.