Skip to content

Instantly share code, notes, and snippets.

@justdoit0823
Created July 10, 2017 09:10
Show Gist options
  • Save justdoit0823/4580b0a2675ac6e59f087e7cab7a7c07 to your computer and use it in GitHub Desktop.
Save justdoit0823/4580b0a2675ac6e59f087e7cab7a7c07 to your computer and use it in GitHub Desktop.
How to get new primary key value after flush session in sqlalchemy
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