- attached models.py
Django migrations fail if AutoSlugField has manager set
I just updated from 1.7.2 to 1.8.0 and some models where I have specified a 'manager' argument on the AutoSlugField now break Django migrations. The situation is:
class SomeModel(models.Model):
objects = SomeCustomManager()
all_objects = models.Manager()
slug = AutoSlugField(populate_from=_autoslug_function, manager=all_objects)
Then when I try to do a makemigrations:
$ python manage.py makemigrations polls
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/tmp/foo/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/tmp/foo/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/tmp/foo/local/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/tmp/foo/local/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/tmp/foo/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 125, in handle
migration_name=self.migration_name,
File "/tmp/foo/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 43, in changes
changes = self._detect_changes(convert_apps, graph)
File "/tmp/foo/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 142, in _detect_changes
self.generate_renamed_models()
File "/tmp/foo/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 417, in generate_renamed_models
model_fields_def = self.only_relation_agnostic_fields(model_state.fields)
File "/tmp/foo/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 80, in only_relation_agnostic_fields
deconstruction = self.deep_deconstruct(field)
File "/tmp/foo/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 67, in deep_deconstruct
for key, value in kwargs.items()
File "/tmp/foo/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 67, in <dictcomp>
for key, value in kwargs.items()
File "/tmp/foo/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 61, in deep_deconstruct
path, args, kwargs = deconstructed
ValueError: too many values to unpack
The problem seems to be: AutoSlugField.deconstruct includes the 'manager' argument in the kwargs it returns; that is recursively passed into django.db.migrations.autodetector.MigrationAutodetector.deep_deconstruct. Since Mangers have a .deconstruct() method, it is called and returns the wrong kind of result.
The most obvious solution I see is to not include 'manager' in AutoSlugField.deconstruct. I don't see why the details of the manager would be important to the migration, but I might be missing a use-case.
Comments (6)
-
reporter -
Workaround for now:
from autoslug import AutoSlugField as RealAutoSlugField class AutoSlugField(RealAutoSlugField): # XXX: Work around https://bitbucket.org/neithere/django-autoslug/issues/34/django-migrations-fail-if-autoslugfield def deconstruct(self): name, path, args, kwargs = super(AutoSlugField, self).deconstruct() if 'manager' in kwargs: del kwargs['manager'] return name, path, args, kwargs
-
Any idea if this will get fixed in the main branch? We're using our own fork for now.
-
This should be fixed once this pull request gets merged:
-
repo owner Thanks for the pull request, merged into master.
-
repo owner - changed status to resolved
- Log in to comment
Exact models.py used to trigger the traceback in the issue report