#27167: Removing Validator callable breaks Migrations
----------------------------+------------------------
Reporter: kamandol | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Keywords: validators
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------
Adding a Validator callable to one of my models :
libdump/models.py
{{{#!python
...
def validate_platform_choices(value):
if value not in PLATFORMS:
raise ValidationError("%s not in %s" % (value, PLATFORMS))
class Project(models.Model):
name = models.CharField(max_length=128)
platform = models.CharField(max_length=64, choices=PLATFORM_CHOICES,
validators=[validate_platform_choices])
...
}}}
Produces the following migration:
libdump/migrations/0002_auto_20160901_1555.py
{{{#!python
# -*- coding: utf-8 -*-
# Generated by Django 1.9.8 on 2016-09-01 15:55
from __future__ import unicode_literals
from django.db import migrations, models
import libdump.models
class Migration(migrations.Migration):
dependencies = [
('libdump', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='project',
name='platform',
field=models.CharField(choices=[('ios', 'IOS'), ('android',
'ANDROID'), ('amazon', 'AMAZON')], max_length=64,
validators=[libdump.models.validate_platform_choices]),
),
]
}}}
If I want to remove the Validator AND the callable, trying to run
makemigrations produces the following error:
{{{
$ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/ricardo/.virtualenvs/libdump/lib/python3.5/site-
packages/django/core/management/__init__.py", line 353, in
execute_from_command_line
utility.execute()
File "/Users/ricardo/.virtualenvs/libdump/lib/python3.5/site-
packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/ricardo/.virtualenvs/libdump/lib/python3.5/site-
packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/ricardo/.virtualenvs/libdump/lib/python3.5/site-
packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/Users/ricardo/.virtualenvs/libdump/lib/python3.5/site-
packages/django/core/management/commands/makemigrations.py", line 65, in
handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File "/Users/ricardo/.virtualenvs/libdump/lib/python3.5/site-
packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/Users/ricardo/.virtualenvs/libdump/lib/python3.5/site-
packages/django/db/migrations/loader.py", line 170, in build_graph
self.load_disk()
File "/Users/ricardo/.virtualenvs/libdump/lib/python3.5/site-
packages/django/db/migrations/loader.py", line 105, in load_disk
migration_module = import_module("%s.%s" % (module_name,
migration_name))
File
"/Users/ricardo/.virtualenvs/libdump/lib/python3.5/importlib/__init__.py",
line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in
_find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in
_call_with_frames_removed
File "/Users/ricardo/ToolsDev/sp-tool-
libdump/libdump/migrations/0002_auto_20160901_1555.py", line 9, in
<module>
class Migration(migrations.Migration):
File "/Users/ricardo/ToolsDev/sp-tool-
libdump/libdump/migrations/0002_auto_20160901_1555.py", line 19, in
Migration
field=models.CharField(choices=[('ios', 'IOS'), ('android',
'ANDROID'), ('amazon', 'AMAZON')], max_length=64,
validators=[libdump.models.validate_platform_choices]),
AttributeError: module 'libdump.models' has no attribute
'validate_platform_choices
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27167>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.1b4387b46e56f632f3618be084632c8e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.