malthe / pickle.py secret
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View pickle.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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)." % (
cls.__name__,
", ".join(map(repr, args))
))
 
return inst
 
 
def get_instance_query(inst):
return (
get_instance,
(type(inst), tuple(getattr(inst, name) for name in (
column.name 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
Something went wrong with that request. Please try again.