I'll try to explain, hopefully this is the right answer.

My guess is that you are seeing the identity as a tuple of primary keys and 
that can be confusing. If so, that's because 
'orm.state.InstanceState.identity` just returns the primary key. SqlAlchemy 
actually tracks it the identity in a more complex way.

Once you call `session.flush()` after adding the record to one of your 
sessions(s), it is (hopefully) created in the db. A primary key is 
generated (if its a serial) or the provided key is entered.  Any backend DB 
logic (such as constraints) executes and SqlAlchemy gets a "OK!".  If the 
key is a serial, your driver will probably show sql calls that use the 
`RETURNING colname` syntax.  I think I saw other methods of 
getting/generating sequence ids, but I can't remember.

SqlAlchemy doesn't seem to track objects in the map until it talks to the 
db.  If you add an object to a session, it won't be in the identity map -- 
regardless of you specifying a primary key or expecting one to be 
autogenerated.  It's not until flush() is called (or implied via commit()) 
that `.identity` has a value.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to