Created
July 10, 2017 09:10
-
-
Save justdoit0823/4580b0a2675ac6e59f087e7cab7a7c07 to your computer and use it in GitHub Desktop.
How to get new primary key value after flush session in sqlalchemy
This file contains hidden or 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
from sqlalchemy.orm.base import instance_state | |
def get_instance_identity(instance, single=True): | |
"""获取实例主键值。""" | |
identity = instance_state(instance).identity | |
if single: | |
return identity[0] | |
return identity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment