#23418: Classes embedded inside other classes are not serialized correctly
----------------------------+--------------------
Reporter: dlo | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
Simple example:
{{{
class Store(models.Model):
@deconstructible
class IgnoreFormatString(object):
def __init__(self, s):
self.s = s
def __str__(self):
return self.s
def __mod__(self, k):
return self
name = models.CharField(max_length=64, null=True)
rating = models.IntegerField(error_messages={'invalid':
IgnoreFormatString("You've entered an invalid value.")}, null=True)
}}}
The migration is created appropriately, but running it will fail with
something like the following:
{{{
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "my_project/lib/python2.7/site-
packages/django/core/management/__init__.py", line 385, in
execute_from_command_line
utility.execute()
File "my_project/lib/python2.7/site-
packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "my_project/lib/python2.7/site-
packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "my_project/lib/python2.7/site-
packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "my_project/lib/python2.7/site-
packages/django/core/management/commands/migrate.py", line 63, in handle
executor = MigrationExecutor(connection,
self.migration_progress_callback)
File "my_project/lib/python2.7/site-
packages/django/db/migrations/executor.py", line 17, in __init__
self.loader = MigrationLoader(self.connection)
File "my_project/lib/python2.7/site-
packages/django/db/migrations/loader.py", line 48, in __init__
self.build_graph()
File "my_project/lib/python2.7/site-
packages/django/db/migrations/loader.py", line 173, in build_graph
self.load_disk()
File "my_project/lib/python2.7/site-
packages/django/db/migrations/loader.py", line 103, in load_disk
migration_module = import_module("%s.%s" % (module_name,
migration_name))
File
"/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py",
line 37, in import_module
__import__(name)
File "my_project/app/migrations/0001_initial.py", line 8, in <module>
class Migration(migrations.Migration):
File "my_project/app/migrations/0001_initial.py", line 19, in Migration
('rating', models.IntegerField(null=True, error_messages={b'invalid':
app.models.IgnoreFormatString(b"You've entered an invalid value.")})),
AttributeError: 'module' object has no attribute 'IgnoreFormatString
}}}
Let me know if you need anything else to help diagnose the issue or have
any questions. Cheers!
--
Ticket URL: <https://code.djangoproject.com/ticket/23418>
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/046.9b98002c2ad46b6e542a759cc7d4706b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.