[Django] #21786: migrate fails with certain mixin/model combinations

15 views
Skip to first unread message

Django

unread,
Jan 15, 2014, 7:42:05 PM1/15/14
to django-...@googlegroups.com
#21786: migrate fails with certain mixin/model combinations
-----------------------------+------------------------
Reporter: gabejackson | Owner:
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Keywords: migrations
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------
manage migrate fails with:
{{{
Operations to perform:
Synchronize unmigrated apps: admin, contenttypes, langapp, auth,
sessions
Apply all migrations: (none)
Synchronizing apps without migrations:
Creating tables...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table langapp_mymodela_translation
Creating table langapp_mymodela
Creating table langapp_mymodelb_translation
Creating table langapp_mymodelb
Creating table langapp_mymodelc
Creating table langapp_mymodeld
Installing custom SQL...
Installing indexes...
Installed 0 object(s) from 0 fixture(s)
Running migrations:
No migrations needed.
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-
packages/django/core/management/__init__.py", line 427, in
execute_from_command_line
utility.execute()
File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-
packages/django/core/management/__init__.py", line 419, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-
packages/django/core/management/base.py", line 244, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-
packages/django/core/management/base.py", line 291, in execute
output = self.handle(*args, **options)
File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-
packages/django/core/management/commands/migrate.py", line 140, in handle
changes = autodetector.changes(graph=executor.loader.graph)
File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-
packages/django/db/migrations/autodetector.py", line 33, in changes
changes = self._detect_changes()
File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-
packages/django/db/migrations/autodetector.py", line 62, in
_detect_changes
if not new_apps.get_model(al, mn)._meta.proxy
File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-
packages/django/apps/registry.py", line 183, in get_model
return self.get_app_config(app_label).get_model(model_name.lower())
File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-
packages/django/apps/base.py", line 125, in get_model
"App '%s' doesn't have a '%s' model." % (self.label, model_name))
LookupError: App 'langapp' doesn't have a 'mymodela' model.
}}}

given the following models.py:

{{{
from django.db import models
from hvad.models import TranslatableModel, TranslatedFields

class MyMixin(object):
pass

# Fails
class MyModelA(TranslatableModel, MyMixin):
translations = TranslatedFields(
name=models.CharField(max_length=60),
)

# Works
class MyModelB(TranslatableModel):
translations = TranslatedFields(
name=models.CharField(max_length=60),
)

# Works
class MyModelC(models.Model, MyMixin):
name=models.CharField(max_length=60),

# Works obviously
class MyModelD(models.Model):
name=models.CharField(max_length=60),
}}}

Removing MyMixin from MyModelA and re-running migrate works (deleted the
sqlite db first):

{{{
Operations to perform:
Synchronize unmigrated apps: admin, contenttypes, langapp, auth,
sessions
Apply all migrations: (none)
Synchronizing apps without migrations:
Creating tables...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table langapp_mymodela_translation
Creating table langapp_mymodela
Creating table langapp_mymodelb_translation
Creating table langapp_mymodelb
Creating table langapp_mymodelc
Creating table langapp_mymodeld
Installing custom SQL...
Installing indexes...
Installed 0 object(s) from 0 fixture(s)
Running migrations:
No migrations needed.

You have installed Django's auth system, and don't have any superusers
defined.
Would you like to create one now? (yes/no): no
}}}

These tests have been conducted with hvad master (github) and django
master (github)

--
Ticket URL: <https://code.djangoproject.com/ticket/21786>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 15, 2014, 7:43:39 PM1/15/14
to django-...@googlegroups.com
#21786: migrate fails with certain mixin/model combinations
-----------------------------+--------------------------------------

Reporter: gabejackson | Owner:
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: migrations | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by gabejackson):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

posted after discussion with andrewgodwin in #django-dev

some thoughts:
- migrate still runs models through a serialise/deserialise cycle
- it runs autodetect to see if you have changes
- perhaps not serialising properly

--
Ticket URL: <https://code.djangoproject.com/ticket/21786#comment:1>

Django

unread,
Jan 15, 2014, 7:58:39 PM1/15/14
to django-...@googlegroups.com
#21786: migrate fails with certain mixin/model combinations
-----------------------------+----------------------------------------
Reporter: gabejackson | Owner: andrewgodwin
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: migrations | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+----------------------------------------
Changes (by andrewgodwin):

* owner: => andrewgodwin
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/21786#comment:2>

Django

unread,
Jan 16, 2014, 8:07:19 AM1/16/14
to django-...@googlegroups.com
#21786: migrate fails with certain mixin/model combinations
-----------------------------+----------------------------------------
Reporter: gabejackson | Owner: andrewgodwin
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migrations | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+----------------------------------------
Changes (by timo):

* cc: timo (added)
* stage: Unreviewed => Accepted


Comment:

I also ran across a similar issue but didn't distill it to a simple
example like Gabe has done.

--
Ticket URL: <https://code.djangoproject.com/ticket/21786#comment:3>

Django

unread,
Jan 19, 2014, 12:52:34 PM1/19/14
to django-...@googlegroups.com
#21786: migrate fails with certain mixin/model combinations
-----------------------------+----------------------------------------
Reporter: gabejackson | Owner: andrewgodwin
Type: Bug | Status: assigned
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: migrations | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+----------------------------------------

Comment (by andrewgodwin):

I can't replicate this, as django-hvad doesn't work against 1.7 trunk. Can
it be reduced to something that doesn't depend on an external app?

--
Ticket URL: <https://code.djangoproject.com/ticket/21786#comment:4>

Django

unread,
Jan 19, 2014, 1:12:33 PM1/19/14
to django-...@googlegroups.com
#21786: migrate fails with certain mixin/model combinations
-----------------------------+----------------------------------------
Reporter: gabejackson | Owner: andrewgodwin
Type: Bug | Status: assigned
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: migrations | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+----------------------------------------

Comment (by andrewgodwin):

Nevermind, I managed to get it working enough to debug the issue -
migrations ignores any abstract bases (which TranslatableModel is one of),
and if there's no bases at all adds models.Model as a base, but if you had
a mixin it had bases but none were from Model. I've pushed a fix.

Looking at the hvad code, I wouldn't be surprised if it needs other
updates for 1.7 as it's doing some weird things with models, but that's to
be expected, I guess. It at least doesn't immediately fail now.

--
Ticket URL: <https://code.djangoproject.com/ticket/21786#comment:5>

Django

unread,
Jan 19, 2014, 1:13:10 PM1/19/14
to django-...@googlegroups.com
#21786: migrate fails with certain mixin/model combinations
-----------------------------+----------------------------------------
Reporter: gabejackson | Owner: andrewgodwin
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: migrations | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+----------------------------------------
Changes (by Andrew Godwin <andrew@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"1f5268a01f82c314b48d195b7d7a344f9db58b6d"]:
{{{
#!CommitTicketReference repository=""
revision="1f5268a01f82c314b48d195b7d7a344f9db58b6d"
Fixed #21786: Bad behaviour when mixins + abstract bases for migrations
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21786#comment:6>

Reply all
Reply to author
Forward
0 new messages