#24701: Migration created on python2.7 fail to load on python 3 due to
models.Manager
----------------------------+--------------------------------------
     Reporter:  aeby        |                    Owner:  nobody
         Type:  Bug         |                   Status:  new
    Component:  Migrations  |                  Version:  1.8
     Severity:  Normal      |               Resolution:
     Keywords:              |             Triage Stage:  Unreviewed
    Has patch:  0           |      Needs documentation:  0
  Needs tests:  0           |  Patch needs improvement:  0
Easy pickings:  0           |                    UI/UX:  0
----------------------------+--------------------------------------

Comment (by aeby):

 === On python 2.7 ===

 ''models.py''
 {{{#!python
 from django.db import models


 class MyManager(models.Manager):
     use_in_migrations = True

     def something(self):
         print('demo manager')


 class MyModel(models.Model):
     demo = models.BooleanField(default=True)

     objects = MyManager()
 }}}

 ''0001_initial.py''
 {{{#!python
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals

 from django.db import models, migrations
 import demo.models


 class Migration(migrations.Migration):

     dependencies = [
     ]

     operations = [
         migrations.CreateModel(
             name='MyModel',
             fields=[
                 ('id', models.AutoField(verbose_name='ID',
 serialize=False, auto_created=True, primary_key=True)),
                 ('demo', models.BooleanField(default=True)),
             ],
             managers=[
                 (b'objects', demo.models.MyManager()),
             ],
         ),
     ]
 }}}

 === On python 3.4 ===
 ''$ ./manage.py migrate demo''
 {{{#!bash
 Operations to perform:
   Apply all migrations: demo
 Running migrations:
   Rendering model states...Traceback (most recent call last):
   File "./manage.py", line 35, in <module>
     execute_from_command_line(sys.argv)
   File "/home/aeby/code/myproject/venv/lib/python3.4/site-
 packages/django/core/management/__init__.py", line 338, in
 execute_from_command_line
     utility.execute()
   File "/home/aeby/code/myproject/venv/lib/python3.4/site-
 packages/django/core/management/__init__.py", line 330, in execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File "/home/aeby/code/myproject/venv/lib/python3.4/site-
 packages/django/core/management/base.py", line 390, in run_from_argv
     self.execute(*args, **cmd_options)
   File "/home/aeby/code/myproject/venv/lib/python3.4/site-
 packages/django/core/management/base.py", line 441, in execute
     output = self.handle(*args, **options)
   File "/home/aeby/code/myproject/venv/lib/python3.4/site-
 packages/django/core/management/commands/migrate.py", line 221, in handle
     executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
   File "/home/aeby/code/myproject/venv/lib/python3.4/site-
 packages/django/db/migrations/executor.py", line 104, in migrate
     state = migration.mutate_state(state, preserve=do_run)
   File "/home/aeby/code/myproject/venv/lib/python3.4/site-
 packages/django/db/migrations/migration.py", line 83, in mutate_state
     operation.state_forwards(self.app_label, new_state)
   File "/home/aeby/code/myproject/venv/lib/python3.4/site-
 packages/django/db/migrations/operations/models.py", line 53, in
 state_forwards
     list(self.managers),
   File "/home/aeby/code/myproject/venv/lib/python3.4/site-
 packages/django/db/migrations/state.py", line 81, in add_model
     self.reload_model(app_label, model_name)
   File "/home/aeby/code/myproject/venv/lib/python3.4/site-
 packages/django/db/migrations/state.py", line 140, in reload_model
     self.apps.render_multiple(states_to_be_rendered)
   File "/home/aeby/code/myproject/venv/lib/python3.4/site-
 packages/django/db/migrations/state.py", line 250, in render_multiple
     model.render(self)
   File "/home/aeby/code/myproject/venv/lib/python3.4/site-
 packages/django/db/migrations/state.py", line 533, in render
     body,
   File "/home/aeby/code/myproject/venv/lib/python3.4/site-
 packages/django/db/models/base.py", line 189, in __new__
     new_class.add_to_class(obj_name, obj)
   File "/home/aeby/code/myproject/venv/lib/python3.4/site-
 packages/django/db/models/base.py", line 324, in add_to_class
     value.contribute_to_class(cls, name)
   File "/home/aeby/code/myproject/venv/lib/python3.4/site-
 packages/django/db/models/manager.py", line 169, in contribute_to_class
     setattr(model, name, ManagerDescriptor(self))
 TypeError: attribute name must be string, not 'bytes'
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24701#comment:2>
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/062.01c92db8161fa82d15fb71fdb61746ce%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to