Shafiul
Shafiul

Reputation: 2890

SQLAlchemy get added object's id without committing session

I need ID of an object which I've just added using session.add(). I need the auto-increment ID of this object before committing session.

If I called the object instance.id, I get None.

Is there a way to get ID of a object without committing?

Upvotes: 10

Views: 7586

Answers (1)

Matthias Urlichs
Matthias Urlichs

Reputation: 2524

Simple answer: call session.flush().

Upvotes: 17

Related Questions