The oddity is that calling `__reduce_ex__` on the instance is fine, but on
the class it is not. When serialising a declarative class it finds itself
serialising the class type, which fails. This actually fails for the
`object`, too (see below).

So I think what's happening is that serialisation fails because
`_sa_instance_state`
(somewhere inside it) contains a class. This is probably a yaml bug, then.

In [1]: object().__reduce_ex__(2)
Out[1]: (<function copy_reg.__newobj__>, (object,), None, None, None)

In [2]: object.__reduce_ex__(2)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-eebec0cadfee> in <module>()
----> 1 object.__reduce_ex__(2)

/usr/lib/python2.7/copy_reg.pyc in _reduce_ex(self, proto)
     68     else:
     69         if base is self.__class__:
---> 70             raise TypeError, "can't pickle %s objects" %
base.__name__
     71         state = base(self)
     72     args = (self.__class__, base, state)

TypeError: can't pickle int objects


On 24 October 2014 17:55, Jonathan Vanasco <jvana...@gmail.com> wrote:

>
> On Friday, October 24, 2014 10:39:43 AM UTC-4, Peter Waller wrote:
>>
>> I was also hoping to "just use yaml" to avoid writing custom dumping
>> code, since it seems in general like a useful capability. So I may yet try
>> and find the underlying bug and fix it.
>>
>
> It might not be a bug, and the effect of an "implementation feature" of
> SqlAlchemy.  I tried (naively) playing around with your example, and
> thought back to how SqlAlchemy accomplishes much of it's magic by creating
> custom comparators (and other private methods) on the classes and columns.
>
> Playing around with it, the problem seems to be with the SqlAlchemy
> object's __reduce_ex__ method. If you simply use __reduce__ in yaml, it
> works.  I couldn't figure out what Foo inherits __reduce_ex__ from , or if
> any of the columns have it.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to