Instantly share code, notes, and snippets.

@malthe malthe/ Secret
Created Mar 28, 2014

What would you like to do?
def get_instance(cls, args):
inst = cls.query.get_raw(args)
if inst is None:
raise ValueError(
"Query for type '%s' returned no items for "
"primary key: (%s)." % (
", ".join(map(repr, args))
return inst
def get_instance_query(inst):
return (
(type(inst), tuple(getattr(inst, name) for name in ( for column in inst.__mapper__.primary_key
Model.__reduce__ = get_instance_query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment