[Django] #23418: Classes embedded inside other classes are not serialized correctly

14 views
Skip to first unread message

Django

unread,
Sep 4, 2014, 1:36:40 PM9/4/14
to django-...@googlegroups.com
#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.

Django

unread,
Sep 5, 2014, 5:57:28 PM9/5/14
to django-...@googlegroups.com
#23418: Classes embedded inside other classes are not serialized correctly
----------------------------+--------------------------------------
Reporter: dlo | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.7
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by andrewgodwin):

* status: new => closed
* needs_better_patch: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_docs: => 0


Comment:

Unfortunately, this is unserializable, as there's no way to get the
reference to the surrounding class from the inner class. I'll update the
docs to mention this, but the only fix for you is to move
InvalidFormatString to the outer scope.

--
Ticket URL: <https://code.djangoproject.com/ticket/23418#comment:1>

Django

unread,
Sep 5, 2014, 6:00:19 PM9/5/14
to django-...@googlegroups.com
#23418: Classes embedded inside other classes are not serialized correctly
----------------------------+--------------------------------------
Reporter: dlo | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.7
Severity: Normal | Resolution: invalid
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 Andrew Godwin <andrew@…>):

In [changeset:"45768e6b72607b4bc913358c560830454f3336a7"]:
{{{
#!CommitTicketReference repository=""
revision="45768e6b72607b4bc913358c560830454f3336a7"
Update docs to be more clear about nested classes (refs #23418)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23418#comment:2>

Django

unread,
Sep 5, 2014, 6:38:07 PM9/5/14
to django-...@googlegroups.com
#23418: Classes embedded inside other classes are not serialized correctly
----------------------------+--------------------------------------
Reporter: dlo | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.7
Severity: Normal | Resolution: invalid
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 Andrew Godwin <andrew@…>):

In [changeset:"e5cdfb151039cdd22a17480f0f1fb9ccbad5eb56"]:
{{{
#!CommitTicketReference repository=""
revision="e5cdfb151039cdd22a17480f0f1fb9ccbad5eb56"
[1.7.x] Update docs to be more clear about nested classes (refs #23418)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23418#comment:3>

Django

unread,
Sep 5, 2014, 8:53:51 PM9/5/14
to django-...@googlegroups.com
#23418: Classes embedded inside other classes are not serialized correctly
----------------------------+--------------------------------------
Reporter: dlo | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.7
Severity: Normal | Resolution: invalid
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 dlo):

@Andrew Any way we can prevent the migration itself from being created as
well? Although the docs mention it now, the migration is still created and
users won't encounter the error until after running it. Thoughts?

--
Ticket URL: <https://code.djangoproject.com/ticket/23418#comment:4>

Django

unread,
Sep 6, 2014, 8:49:41 PM9/6/14
to django-...@googlegroups.com
#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 | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by dlo):

* status: closed => new
* resolution: invalid =>


Comment:

Reopening since I'm not convinced a doc-only change is sufficient. I'm
happy to contribute a patch if needed.

--
Ticket URL: <https://code.djangoproject.com/ticket/23418#comment:5>

Django

unread,
Sep 7, 2014, 9:05:45 PM9/7/14
to django-...@googlegroups.com
#23418: Classes embedded inside other classes are not serialized correctly
-------------------------------------+-------------------------------------
Reporter: dlo | Owner:
Type: | Markush2010
Cleanup/optimization | Status: assigned
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Markush2010):

* owner: nobody => Markush2010
* cc: info+coding@… (added)
* has_patch: 0 => 1
* status: new => assigned
* type: Bug => Cleanup/optimization


Comment:

I opened a pull-request: https://github.com/django/django/pull/3194

--
Ticket URL: <https://code.djangoproject.com/ticket/23418#comment:6>

Django

unread,
Sep 7, 2014, 9:23:25 PM9/7/14
to django-...@googlegroups.com
#23418: Classes embedded inside other classes are not serialized correctly
-------------------------------------+-------------------------------------
Reporter: dlo | Owner:
Type: | Markush2010
Cleanup/optimization | Status: assigned
Component: Migrations | Version: 1.7

Severity: Normal | Resolution:
Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by dlo):

Awesome, thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/23418#comment:7>

Django

unread,
Sep 8, 2014, 3:36:30 PM9/8/14
to django-...@googlegroups.com
#23418: Classes embedded inside other classes are not serialized correctly
-------------------------------------+-------------------------------------
Reporter: dlo | Owner:
Type: | Markush2010
Cleanup/optimization | Status: closed
Component: Migrations | Version: 1.7
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Markus Holtermann <info@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"d28b5f13b332bda4317949b98e33f528d30ec006"]:
{{{
#!CommitTicketReference repository=""
revision="d28b5f13b332bda4317949b98e33f528d30ec006"
Fixed #23418 -- Fail when migration deconstruct produces invalid import
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23418#comment:8>

Django

unread,
Sep 8, 2014, 3:41:41 PM9/8/14
to django-...@googlegroups.com
#23418: Classes embedded inside other classes are not serialized correctly
-------------------------------------+-------------------------------------
Reporter: dlo | Owner:
Type: | Markush2010
Cleanup/optimization | Status: closed
Component: Migrations | Version: 1.7

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"b0def3bcac1a2e1117050e00fa1b187a897f0c2e"]:
{{{
#!CommitTicketReference repository=""
revision="b0def3bcac1a2e1117050e00fa1b187a897f0c2e"
[1.7.x] Fixed #23418 -- Fail when migration deconstruct produces invalid
import

Backport of d28b5f13b3 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23418#comment:9>

Django

unread,
Sep 8, 2014, 4:51:35 PM9/8/14
to django-...@googlegroups.com
#23418: Classes embedded inside other classes are not serialized correctly
-------------------------------------+-------------------------------------
Reporter: dlo | Owner:
Type: | Markush2010
Cleanup/optimization | Status: closed
Component: Migrations | Version: 1.7

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"16548cfc7c9d86ae7b0d13425ec7608f0571130c"]:
{{{
#!CommitTicketReference repository=""
revision="16548cfc7c9d86ae7b0d13425ec7608f0571130c"
Fixed broken test from da160d440f; refs #23418.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23418#comment:10>

Django

unread,
Sep 8, 2014, 4:53:19 PM9/8/14
to django-...@googlegroups.com
#23418: Classes embedded inside other classes are not serialized correctly
-------------------------------------+-------------------------------------
Reporter: dlo | Owner:
Type: | Markush2010
Cleanup/optimization | Status: closed
Component: Migrations | Version: 1.7

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"1f1a32928873a4e7cfe2f8f15631aa63df335490"]:
{{{
#!CommitTicketReference repository=""
revision="1f1a32928873a4e7cfe2f8f15631aa63df335490"
[1.7.x] Fixed broken test from da160d440f; refs #23418.

Backport of 16548cfc7c from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23418#comment:11>

Django

unread,
Sep 10, 2014, 1:10:41 PM9/10/14
to django-...@googlegroups.com
#23418: Classes embedded inside other classes are not serialized correctly
-------------------------------------+-------------------------------------
Reporter: dlo | Owner:
Type: | Markush2010
Cleanup/optimization | Status: closed
Component: Migrations | Version: 1.7

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"fbeb7979ee43cb386265ff7aec757e35b4cf61f8"]:
{{{
#!CommitTicketReference repository=""
revision="fbeb7979ee43cb386265ff7aec757e35b4cf61f8"
Avoided using deprecated version of importlib; refs #23418.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23418#comment:12>

Django

unread,
Sep 10, 2014, 1:10:58 PM9/10/14
to django-...@googlegroups.com
#23418: Classes embedded inside other classes are not serialized correctly
-------------------------------------+-------------------------------------
Reporter: dlo | Owner:
Type: | Markush2010
Cleanup/optimization | Status: closed
Component: Migrations | Version: 1.7

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"4500784b24856b23924e7d36b405f2df1499ea83"]:
{{{
#!CommitTicketReference repository=""
revision="4500784b24856b23924e7d36b405f2df1499ea83"
[1.7.x] Avoided using deprecated version of importlib; refs #23418.

Backport of fbeb7979ee from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23418#comment:13>

Reply all
Reply to author
Forward
0 new messages