sqlalchemy return new id code example
Example 1: sqlalchemy return id after insert
f = Foo(bar='x')
session.add(f)
session.flush()
print(f.id) # will return the obj id
Example 2: sqlalchemy return id after insert
session.flush()
print(f.id)
f = Foo(bar='x')
session.add(f)
session.flush()
print(f.id) # will return the obj id
session.flush()
print(f.id)