We would like to freeze the results of a query to my database in a yaml
file, so that we can use the results in an app which isn't connected to the
database.

It makes sense here to reuse the model classes. Here's an example:

class Foo(declarative_base()):
    __tablename__ = "foo"
    id = S.Column(S.Integer, primary_key=True)

Unfortunately, `yaml.dump(Foo())` gives a surprising result:

/usr/lib/python3/dist-packages/yaml/representer.py in
represent_object(self, data)
    311             reduce = copyreg.dispatch_table[cls](data)
    312         elif hasattr(data, '__reduce_ex__'):
--> 313             reduce = data.__reduce_ex__(2)
    314         elif hasattr(data, '__reduce__'):
    315             reduce = data.__reduce__()

/usr/lib/python3.4/copyreg.py in _reduce_ex(self, proto)
     63     else:
     64         if base is self.__class__:
---> 65             raise TypeError("can't pickle %s objects" %
base.__name__)
     66         state = base(self)
     67     args = (self.__class__, base, state)

TypeError: can't pickle int objects

It seems that what is happening is that `data` is equal to `Foo`, and
`Foo.__reduce_ex__(2)` gives `TypeError: can't pickle int objects`. As does
`declarative_base().__reduce_ex__(2)`.

I note that `pickle.dumps` works. But we'd rather use YAML.

Where is the bug? Is it in sqlalchemy, yaml, or python?

Thanks,

- Peter

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to