{{{
>>> 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.
* 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>
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>