I'm having a strange caching problem when using SQLAlchemy with Apache and mod_python. Using the ORM, I have a class that maps to a simple table with two columns and no foreign keys. When I get an HTTP request, I get the desired object by primary key and return the value of the attribute that maps to the other column. This works fine when Apache first loads, but if the value stored in the column of the desired object changes (e.g. by simply running an UPDATE in the MySQL command line), the new value will not be returned in the code. Here's a synopsis of the code:
######## engine = sa.create_engine('mysql://[EMAIL PROTECTED]/project', encoding='utf-8', echo=False) metadata = MetaData() metadata.bind = get_engine() users_table = Table('users', metadata, Column('id', Integer, primary_key=True), Column('mojo', Integer, nullable=False, default=0), mysql_engine='InnoDB' ) class User(object): def __init__(self, id): self.id = id self.mojo = 0 def toResult(self): return {'user_id': self.id, 'mojo': self.mojo, 'result_code': 0, } mapper(User, users_table) Session = sessionmaker(bind=engine, autoflush=True, transactional=True) def log_debug(msg): # custom logging function that logs to a file using the std lib "logging" module def get_user(user_id): db = Session() user = db.query(User).filter(User.id == user_id).first() res = user.toResult() log_debug("pelf_requests.balance", res) db.close() return res ######## The funny part is that if I run this very same code in a standalone Python process (where the process is kept alive, like the Apache process), there is no caching behavior; the correct value is returned every single time. If it's run in Apache, I can see the incorrect value get returned in the logs (in the 'get_user' function above). In either case, I see the query getting logged in MySQL's query logs. Any ideas at all? I've searched through both the mod_python and sqlalchemy archives and haven't found anything appropriate. The versions of all pertinent software are listed below: SQLAlchemy: 0.4.2p3-1 (Ubuntu hardy package) Apache: 2.2.4-3 (Ubuntu gutsy) mod_python: 3.3.1-2 (Ubuntu gutsy) Python: 2.5.1-5 (Ubuntu gutsy) Thanks in advance for any insight or suggestions. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---