#28080: Migration guesses wrong namespace for Enum defined on class
------------------------------------------+------------------------
               Reporter:  Curtis Maloney  |          Owner:  nobody
                   Type:  Bug             |         Status:  new
              Component:  Migrations      |        Version:  1.11
               Severity:  Normal          |       Keywords:
           Triage Stage:  Unreviewed      |      Has patch:  0
    Needs documentation:  0               |    Needs tests:  0
Patch needs improvement:  0               |  Easy pickings:  0
                  UI/UX:  0               |
------------------------------------------+------------------------
 I have the following model:

 {{{
 class Question(models.Model):
     @enum.unique
     class MODE(enum.IntEnum):
         TEXT = 1
         NUMBER = 2
         CHOICE = 3

     question = models.TextField()
     label_text = models.CharField(max_length=200)
     hint = models.CharField(max_length=200, blank=True)
     mode = models.IntegerField(
         default=MODE.TEXT,
         choices=((x.value, x.name.title()) for x in MODE),
     )
 }}}

 The initial migration generated produces:

 {{{
         migrations.CreateModel(
             name='Question',
             fields=[
                 ('id', models.AutoField(auto_created=True,
 primary_key=True, serialize=False, verbose_name='ID')),
                 ('question', models.TextField()),
                 ('label_text', models.CharField(max_length=200)),
                 ('hint', models.CharField(blank=True, max_length=200)),
                 ('mode', models.IntegerField(choices=[(1, 'Text'), (2,
 'Number'), (3, 'Choice')], default=sheets.models.MODE(1))),
             ],
         ),
 }}}

 Notice the default... it's sheets.models.MODE instead of
 sheets.models.Question.MODE

 This causes the following traceback:

 {{{
 Traceback (most recent call last):
   File "manage.py", line 22, in <module>
     execute_from_command_line(sys.argv)
   File ".../venv/lib/python3.5/site-
 packages/django/core/management/__init__.py", line 363, in
 execute_from_command_line
     utility.execute()
   File ".../venv/lib/python3.5/site-
 packages/django/core/management/__init__.py", line 355, in execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File ".../venv/lib/python3.5/site-
 packages/django/core/management/base.py", line 283, in run_from_argv
     self.execute(*args, **cmd_options)
   File ".../venv/lib/python3.5/site-
 packages/django/core/management/base.py", line 330, in execute
     output = self.handle(*args, **options)
   File ".../venv/lib/python3.5/site-
 packages/django/core/management/commands/migrate.py", line 83, in handle
     executor = MigrationExecutor(connection,
 self.migration_progress_callback)
   File ".../venv/lib/python3.5/site-
 packages/django/db/migrations/executor.py", line 20, in __init__
     self.loader = MigrationLoader(self.connection)
   File ".../venv/lib/python3.5/site-
 packages/django/db/migrations/loader.py", line 52, in __init__
     self.build_graph()
   File ".../venv/lib/python3.5/site-
 packages/django/db/migrations/loader.py", line 203, in build_graph
     self.load_disk()
   File ".../venv/lib/python3.5/site-
 packages/django/db/migrations/loader.py", line 114, in load_disk
     migration_module = import_module("%s.%s" % (module_name,
 migration_name))
   File ".../venv/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 673, in exec_module
   File "<frozen importlib._bootstrap>", line 222, in
 _call_with_frames_removed
   File ".../cloudselect/sheets/migrations/0001_initial.py", line 10, in
 <module>
     class Migration(migrations.Migration):
   File ".../cloudselect/sheets/migrations/0001_initial.py", line 25, in
 Migration
     ('mode', models.IntegerField(choices=[(1, 'Text'), (2, 'Number'), (3,
 'Choice')], default=sheets.models.MODE(1))),
 AttributeError: module 'sheets.models' has no attribute 'MODE'
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28080>
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.3db675019602c8cc63e97aebb2a550db%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to