On Friday, January 11, 2013 11:25:06 AM UTC-4, Michael Bayer wrote: > > in theory. It's new stuff and was very tricky to get it to work, so feel > free to send a brief test along. >
Here's a minimal example I quickly put together - it retrieves from the database, but the handler doesn't seem to fire, and so the print statement on the second-last line fails. I'm using the standard MySQLdb with MySQL 5.0.43 (sigh, they promise to update soon) - the server is on a Debian box, and the client code is running in Python 1.6.4 on Windows 7 (it's actually the 64-bit Python interpreter bundled with the Maya graphics package): from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Table, Column, Integer, event, create_engine from sqlalchemy.orm import sessionmaker def My_load_instance_handler(instance, context): instance.itsProduction = None #should add itsProduction attribute to all loaded instances print "stamped loaded instance with production" AlchemyBase = declarative_base() event.listen(AlchemyBase, "load", My_load_instance_handler) dbURL = "mysql://User:password@%s/%s" % ("dbServer", "dbName") #replace with actual parameters engine = create_engine(dbURL) AlchemyBase.metadata.bind=engine class MyDataClass(AlchemyBase): __tablename__ = "vw_users" #replace with actual table name id = Column(Integer, primary_key=True) Session = sessionmaker(bind=engine) session = Session() instance = session.query(MyDataClass).first() print instance.id, instance.itsProduction #this fails with no itsProduction attribute session.close() -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/GOcqdckIB0YJ. To post to this group, send email to sqlalchemy@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.