Ticket #1380 (closed defect: fixed)
[PATCH] TG database.py oddity preventing multiple SA databases from being used
|Reported by:||ian||Owned by:||faide|
as of TG 188.8.131.52, database.py contains this bit of code (lines 48-54):
def create_session(): "Creates a session with the appropriate engine" return sqlalchemy.create_session(bind_to=get_engine()) metadata = activemapper.metadata session = activemapper.Objectstore(create_session) activemapper.objectstore = session
Typically, only the metadata needs to be bound to an engine. Remember, metadata keeps track of tables and calls to the database, and session keeps track of class instances and which ones are dirty. When session needs to flush some objects (like when session.flush() is called), it normally just defers to the engine associated with metadata. Since turbogears.database.metadata is already connected to an engine, the custom version of create_session in turbogears.database is unnecessary.
Not only that, but it is preventing us from using DynamicMetaData's connect method, which would allow us to support multple engines. If we just used sqlalchemy's create_session instead of our custom version, we'd be able to call turbogears.metadata.connect("sqlite:///another.sqlite") anytime we wanted. That would let people write decorators that switched out the database on a per-connection basis, for instance to support multiple sites with the same app and let each site have its own database.
Attached is a patch of database.py from TG 184.108.40.206 that removes the unnecessary custom version of create_session, and uses SQLAlchemy's create_session instead.
- Status changed from closed to reopened
- Resolution fixed deleted
- Status changed from reopened to new
- Owner changed from anonymous to faide