Hello, I am puzzled by some behavior of is_modified() I am seeing.
Here is a sample program which illustrates the situation. I'm running this on 0.6.4: ----- import sqlalchemy import sqlalchemy.orm from sqlalchemy import Table, Column, Integer class Spam(object): def __init__(self, cans): self.cans = cans engine = sqlalchemy.create_engine('sqlite:///:memory:') Session = sqlalchemy.orm.sessionmaker(autocommit=False, bind=engine) session = Session() meta = sqlalchemy.MetaData() meta.bind = engine spam_table = Table('spam', meta, Column('id', Integer, primary_key=True), Column('cans', Integer) ) meta.create_all(engine) sqlalchemy.orm.mapper(Spam, spam_table) # Setup finished. Now test things out instance = Spam(42) session.add(instance) session.commit() print "Cans of spam = ", instance.cans instance.cans = 42 print "Has instance been modified? (Should be False): ", session.is_modified(instance) session.commit() instance.cans = 42 print "We have made no net change to the instance..." print "Has instance been modified? (Should be False): ", session.is_modified(instance) ----- When I run this, I get: ----- Cans of spam = 42 Has instance been modified? (Should be False): False We have made no net change to the instance... Has instance been modified? (Should be False): True ----- That's surprising to me. In both cases, no net change is being made to the instance. Noodling around further, it appears that this is triggered by re-using the same instance object, and doing another __setattr__ on the column without having done a __getattr__ on it earlier. I suspect, without having dug around, that after the commit, the instance's attribute values are marked as needing to be re-loaded, but they are not being re-loaded first in order to check whether the new value is in fact different than the existing one. I've also noticed if I re-obtain the instance via a query using .get() on the primary key, the behavior is the expected one, again presumably because the query operation is loading in all the column values. Am I missing something here? Ted -- 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.