Modify

Ticket #190 (new defect)

Opened 3 years ago

Last modified 3 years ago

PyYAML always uses pickle protocol 2 although Python 2.6 only supports 0 and 1

Reported by: Marcus Lindblom Sonestedt <macke@…> Owned by: xi
Priority: normal Component: pyyaml
Severity: normal Keywords:
Cc:

Description

I get this when I save my data, which has no problem with pickle.dump, but bails with yaml. I haven't yet managed to dissect our data structure and find the actual problematic instance.

From the stack-trace (below), it seems as if reduce_ex is called with proto=2, but py 2.6. supports only 0 and 1, and the assert in copy_reg doesn't trigger.

Traceback (most recent call last):
  File "E:\Orsync\Apps\Orsync\src\orsync\model\tests\storage_test.py", line 55, in testWithSubModel
    uber2 = self._copyByDumpLoad(uber)
  File "E:\Orsync\Apps\Orsync\src\orsync\model\tests\storage_test.py", line 14, in _copyByDumpLoad
    data = self.storage.dumps(object)
  File "E:\Orsync\Apps\Orsync\src\orsync\model\storage.py", line 217, in dumps
    return self.yaml.dump(stored_model)
  File "E:\Orsync\_work\3rd\python\yaml\__init__.py", line 175, in dump
    return dump_all([data], stream, Dumper=Dumper, **kwds)
  File "E:\Orsync\_work\3rd\python\yaml\__init__.py", line 165, in dump_all
    dumper.represent(data)
  File "E:\Orsync\_work\3rd\python\yaml\representer.py", line 33, in represent
    node = self.represent_data(data)
  File "E:\Orsync\_work\3rd\python\yaml\representer.py", line 62, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "E:\Orsync\_work\3rd\python\yaml\representer.py", line 228, in represent_dict
    return self.represent_mapping(u'tag:yaml.org,2002:map', data)
  File "E:\Orsync\_work\3rd\python\yaml\representer.py", line 128, in represent_mapping
    node_value = self.represent_data(item_value)
  File "E:\Orsync\_work\3rd\python\yaml\representer.py", line 66, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "E:\Orsync\_work\3rd\python\yaml\representer.py", line 439, in represent_object
    u'tag:yaml.org,2002:python/object:'+function_name, state)
  File "E:\Orsync\_work\3rd\python\yaml\representer.py", line 128, in represent_mapping
    node_value = self.represent_data(item_value)
  File "E:\Orsync\_work\3rd\python\yaml\representer.py", line 66, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "E:\Orsync\_work\3rd\python\yaml\representer.py", line 413, in represent_object
    reduce = data.__reduce_ex__(2)
  File "c:\_work\_unzip\python\python-2.6.2c1-win32.7z\python-2.6.2c1-win32\lib\copy_reg.py", line 70, in _reduce_ex
    raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle int objects

Attachments

Change History

comment:1 Changed 3 years ago by Marcus Lindblom Sonestedt <macke@…>

This is with PyYAML 3.09 on python 2.6.2c1 32-bit on windows, btw.

comment:2 Changed 3 years ago by Marcus Lindblom Sonestedt <macke@…>

  • Severity changed from normal to critical
  • Summary changed from "TypeError: can't pickle int objects" to PyYAML always uses pickle protocol 2 although Python 2.6 only supports 0 and 1

Better summary...

comment:3 Changed 3 years ago by Marcus Lindblom Sonestedt <macke@…>

The error was related to trying to save a class object (a type).

I've worked around it by storing the module+classname separately, instead of attempting to store the type object directly.

comment:4 Changed 3 years ago by xi

  • Severity changed from critical to normal

Serializing a class object works fine for me; a test case needed.

Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class C(object): pass
... 
>>> import yaml; print yaml.dump(C)
!!python/name:__main__.C ''

>>> 
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will be changed from xi. Next status will be 'new'
The owner will be changed from xi to anonymous. Next status will be 'assigned'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.