-
-
Save malthe/b03cad86c4f9c4382045 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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