#28894: Invalid migrations caused by incorrect serialization of
functools.partial()
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: Bug | Status: assigned
Component: | Version: 1.9
Migrations | Keywords: functools partial
Severity: Normal | migrations serialization
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
So this one was interesting... I ended up with a migration that contained
something like this (reduced to a trivial example):
{{{
models.CharField(default=functools.partial(int, *('123', ), **None), ...)
}}}
The expected output should have been:
{{{
models.CharField(default=functools.partial(int, *('123', ), **{}), ...)
}}}
It boils down to the following issue:
{{{
# Python 2.7.6: Empty args working, empty keywords broken.
>>> import functools
>>> print(functools.partial(int, base=10).args)
()
>>> print(functools.partial(int, '123').keywords)
None
}}}
{{{
# Python 2.7.14: Empty args working, empty keywords working.
>>> import functools
>>> print(functools.partial(int, base=10).args)
()
>>> print(functools.partial(int, '123').keywords)
{}
}}}
Scouring the release notes for Python, I found the following:
"The keywords attribute of functools.partial is now always a
dictionary."
This was resolved in 2.7.10, 3.4.4 & 3.5.0.
As Django 2.1 will only support Python 3.5 or later, this only needs to be
backported to 1.11 and 2.0 and need not be applied to master.
Pull request incoming...
--
Ticket URL: <https://code.djangoproject.com/ticket/28894>
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/050.a795bdb77f9cdbd6365fe83de5f20f90%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.