[Django] #27202: yaml dump for django.forms.Field crashes with "TypeError: can't pickle int objects"

19 views
Skip to first unread message

Django

unread,
Sep 9, 2016, 2:34:51 AM9/9/16
to django-...@googlegroups.com
#27202: yaml dump for django.forms.Field crashes with "TypeError: can't pickle int
objects"
-------------------------------+--------------------
Reporter: semenov | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords: yaml
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
Django 1.7.10, PyYAML 3.11 (Python 3.4):

{{{
>>> import yaml
>>> from django import forms
>>> yaml.dump(forms.ChoiceField)
"!!python/name:django.forms.fields.ChoiceField ''\n"
}}}

Django 1.8.14, PyYAML 3.11 (Python 3.5):

{{{
>>> import yaml
>>> from django import forms
>>> yaml.dump(forms.ChoiceField)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/semenov/work/test/var/venv/lib/python3.5/site-
packages/yaml/__init__.py", line 200, in dump
return dump_all([data], stream, Dumper=Dumper, **kwds)
File "/Users/semenov/work/test/var/venv/lib/python3.5/site-
packages/yaml/__init__.py", line 188, in dump_all
dumper.represent(data)
File "/Users/semenov/work/test/var/venv/lib/python3.5/site-
packages/yaml/representer.py", line 26, in represent
node = self.represent_data(data)
File "/Users/semenov/work/test/var/venv/lib/python3.5/site-
packages/yaml/representer.py", line 51, in represent_data
node = self.yaml_multi_representers[data_type](self, data)
File "/Users/semenov/work/test/var/venv/lib/python3.5/site-
packages/yaml/representer.py", line 313, in represent_object
reduce = data.__reduce_ex__(2)
File "/Users/semenov/work/test/var/venv/lib/python3.5/copyreg.py", line
65, in _reduce_ex
raise TypeError("can't pickle %s objects" % base.__name__)
TypeError: can't pickle int objects
}}}

Anything we can do to have Django class types YAML-compatible again?

--
Ticket URL: <https://code.djangoproject.com/ticket/27202>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 9, 2016, 9:10:25 AM9/9/16
to django-...@googlegroups.com
#27202: Investigate RenameMethodsBase effect on yaml serialization
---------------------------+------------------------------------
Reporter: semenov | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 1.8
Severity: Normal | Resolution:
Keywords: yaml | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* component: Uncategorized => Utilities
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

Fixed in Django 1.10 by a3fe4addcb9063fc327c8609c7ebba4d531da4ce.
Unfortunately, Django 1.8 and 1.9 are only receiving security and data
loss fixes by now. Perhaps it's worth investigating the cause of this
(`RenameMethodsBase`, possibly) to try to prevent future regressions.

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

Django

unread,
Jan 28, 2017, 12:17:07 AM1/28/17
to django-...@googlegroups.com
#27202: Investigate RenameMethodsBase effect on yaml serialization
------------------------------+------------------------------------
Reporter: Ilya Semenov | Owner: nobody

Type: Bug | Status: new
Component: Utilities | Version: 1.8
Severity: Normal | Resolution:
Keywords: yaml | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------

Comment (by Ryan Castner):

Ok did a bit of investigating, `RenameMethodsBase` inherits from `type`. I
may be crazy but that sounds a lot like
https://docs.python.org/2/library/pickle.html#pickling-and-unpickling-
extension-types. Specifically:


When the Pickler encounters an object of a type it knows nothing about
— such as an extension type — it looks in two places for a hint of how to
pickle it.

Those hints are the `__reduce__` and `__reduce_ex__` methods. The
`__reduce_ex__` method states `method will be called with a single integer
argument, the protocol version`.

And that call seems to fail here
https://github.com/python/cpython/blob/c30098c8c6014f3340a369a31df9c74bdbacc269/Objects/typeobject.c#L4169

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

Reply all
Reply to author
Forward
0 new messages