Michael, Michael Bayer wrote: > On Nov 6, 2007, at 12:20 PM, Werner F. Bruhin wrote: > > >> I insert a raw into a table and then retrieve again but columns which >> are filled by a db trigger don't return the updated values. >> >> The following is a code snippet and I wonder what I am missing. >> >> engine = sa.create_engine(url, encoding='utf8', echo=False) >> Session = sao.sessionmaker(autoflush=True, transactional=True) >> Session.configure(bind=engine) >> session = Session() >> botlot = db.Bottaglot() >> session.save(botlot) >> session.commit() >> >> print 'org' >> print botlot.bottaglotid >> print botlot.updated >> >> botlot2 = session.query(db.Bottaglot).get(botlot.bottaglotid) >> print 'reloaded' >> print botlot2.bottaglotid >> print botlot2.updated >> >> Both columns "updated" will show None instead of at least for >> botlot2 it >> should show the current date which was inserted into that column by >> a db >> trigger. >> >> > > set a PassiveDefault on the triggered column. that will indicate to > the mapper that it should post-fetch the value after an insert. note > that if the trigger is on a primary key column, it wont work since we > need primary key values in order to post-fetch. > PassiveDefault is great to know.
However I still have a problem with the following. In a program I do something like this: botlot3 = session.query(db.Bottaglot).get(39) Then some other user and/or application changes data (I faked this by setting a debugger break point and used the db admin tool to change some data and committed it) in the database and commits, then when I do this: botlot4 = session.query(db.Bottaglot).get(39) I expected to get the data from the database, however SA gets it from the session (I set echo=True) and I don't see a select being done between the first statement and the second. Searching in the documentation I see that it is documented that "get" is NOT querying the database if the key is present, however I haven't found how I can do a primary key query so that SA goes to the database. I'll keep searching in the doc, but would still appreciate any hints. Thanks in advance Werner > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
