#27914: makemigrations produces incorrect path for subclasses of Field which are
inner classes
-------------------------------------+-------------------------------------
Reporter: Serge van | Owner: nobody
den Boom |
Type: | Status: new
Uncategorized |
Component: Database | Version: 1.10
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When you define a subclass from {{{django.db.models.Field}}} as an inner
class of some other class, and use this field inside a
{{{django.db.models.Model}}} class, then when you run {{{manage.py
makemigrations}}}, a migrations file is created which refers to the inner
class as if it were a top-level class of the module it is in.
To reproduce, create the following as your model:
{{{#!python
class Outer(object):
class Inner(models.CharField):
pass
class A(models.Model):
field = Outer.Inner(max_length=20)
}}}
After running {{{manage.py makemigrations}}}, the generated migrations
file contains the following:
{{{#!python
migrations.CreateModel(
name='A',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True,
serialize=False, verbose_name='ID')),
('field', test1.models.Inner(max_length=20)),
],
),
}}}
Note the {{{test1.models.Inner}}}, which should have been
{{{test1.models.Outer.Inner}}}.
The real life case involved an EnumField from django-enumfields, defined
as an inner class of a Django Model class, similar to this:
{{{#!python
import enum
from enumfields import Enum, EnumField
class Thing(models.Model):
@enum.unique
class State(Enum):
on = 'on'
off = 'off'
state = EnumField(enum=State)
}}}
This results in the following migrations code:
{{{#!python
migrations.CreateModel(
name='Thing',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True,
serialize=False, verbose_name='ID')),
('state', enumfields.fields.EnumField(enum=test1.models.State,
max_length=10)),
],
),
}}}
This refers to {{{test1.models.State}}}, instead of to
{{{test1.models.Thing.State}}}.
--
Ticket URL: <https://code.djangoproject.com/ticket/27914>
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/048.b0b86d2d84ba2552df9515650e189a58%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.