I'm hoping someone can clarify my understanding of the Session's identity map. I've created an example to frame my question:
>>> import psycopg2 >>> psycopg2.__version__ '2.2.2 (dt dec ext pq3)' >>> import sqlalchemy >>> sqlalchemy.__version__ '0.6.4' >>> from sqlalchemy import create_engine, MetaData, Table, Column, Integer, >>> String >>> from sqlalchemy.orm import mapper, sessionmaker >>> engine = create_engine('postgresql+psycopg2://ddt:d...@localhost/ddt') >>> metadata = MetaData(engine) >>> t = Table('t', metadata, ... Column('i', Integer, primary_key=True), ... Column('s', String(10))) ... >>> >>> metadata.create_all() >>> class T(object): pass ... >>> >>> mapper(T, t) >>> Session = sessionmaker(bind=engine) >>> session = Session(autocommit=True, autoflush=True, expire_on_commit=True) Now In psql: insert into t values (1, 'a'); insert into t values (2, 'b'); >>> [(t.i, t.s) for t in session.query(T)] [(1, u'a'), (2, u'b')] >>> session.identity_map {(<class '__main__.T'>, (2,)): <sqlalchemy.orm.state.InstanceState object at 0x1c47a90>} The identity_map is holding onto the tail of this list comprehension. This leads some really weird results: In psql: update t set s='c'; >>> [(t.i, t.s) for t in session.query(T)] [(1, u'c'), (2, u'b')] As an end-user, I would either expect both items to be updated or neither of them to be updated. Why is only the last item being held in the identity map? Thanks in advance! Graham -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.