If I try to load this file under python 3.4 I get the error {{{TypeError:
attribute name must be string, not 'bytes}}} from
[https://github.com/django/django/blob/1.8/django/db/models/manager.py#L169
this line].
The problem is that the string 'objects' is prefixed with 'b' on
[https://github.com/django/django/blob/1.8/django/db/migrations/writer.py#L340
this line].
I think this is maybe a bug as all other attribute names are just plain
strings.
--
Ticket URL: <https://code.djangoproject.com/ticket/24701>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Can you please post the entire traceback and the code you are using to
define the model and manager.
--
Ticket URL: <https://code.djangoproject.com/ticket/24701#comment:1>
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>
* stage: Unreviewed => Accepted
Comment:
It looks like we'll need special casing of manager attribute name here
[https://github.com/django/django/blob/8efea1b8d5b5fb0cfef1a3244c339cebf8af36c5/django/db/models/fields/__init__.py#L446
just like we do with model fields].
--
Ticket URL: <https://code.djangoproject.com/ticket/24701#comment:3>
* owner: nobody => MarkusH
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/24701#comment:4>
--
Ticket URL: <https://code.djangoproject.com/ticket/24701#comment:5>
* has_patch: 0 => 1
Comment:
PR: https://github.com/django/django/pull/4558
--
Ticket URL: <https://code.djangoproject.com/ticket/24701#comment:6>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/24701#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"faad6070ee2eeea270c76381f9ca5999bf1ac15f" faad607]:
{{{
#!CommitTicketReference repository=""
revision="faad6070ee2eeea270c76381f9ca5999bf1ac15f"
Fixed #24701 -- Converted model manager names to unicode in migrations
Thanks to Reto Aebersold for reporting the issue and Tim Graham and
Claude Paroz for the review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24701#comment:8>
Comment (by Markus Holtermann <info@…>):
In [changeset:"419f296259d7c22d34d7d1cf46e7cf29e6b26b13" 419f2962]:
{{{
#!CommitTicketReference repository=""
revision="419f296259d7c22d34d7d1cf46e7cf29e6b26b13"
[1.8.x] Fixed #24701 -- Converted model manager names to unicode in
migrations
Thanks to Reto Aebersold for reporting the issue and Tim Graham and
Claude Paroz for the review.
Backport of faad6070ee2eeea270c76381f9ca5999bf1ac15f from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24701#comment:9>
Comment (by aeby):
Wow, you are fast. Thanks & respect!
--
Ticket URL: <https://code.djangoproject.com/ticket/24701#comment:10>