My project requires querying an externally-managed database as well as a 
project-specific database. What I've been doing to date is copying the 
external database (which changes very infrequently) into the 
project-specific database so I only need one engine and one dbsession. I'm 
now trying to correct this monstrosity by binding the external-specific 
classes to the external engine, still using a single session.

Per agronholm's suggestion on IRC, I'm attempting to do this via a base 
class for each database in order to avoid having to individually bind each 
class to the correct engine. Not quite sure how to proceed, though, because 
'binds' isn't accepting my keys when those keys are empty base classes.


from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import (
    scoped_session,
    sessionmaker
)
from zope.sqlalchemy import ZopeTransactionExtension


Base = declarative_base()
DBSession = 
scoped_session(sessionmaker(extension=ZopeTransactionExtension()))


class DB1(Base):
    __abstract__ = True

class DB2(Base):
    __abstract__ = True

class SomeInternalClass(DB1):
    __tablename__ = 'table_in_db1'

class SomeExternalClass(DB2):
    __tablename__ = 'table_in_db2'

db1_engine = engine_from_config(settings, 'sqlalchemy.db1.')
db2_engine = engine_from_config(settings, 'sqlalchemy.db2.')
DBSession.configure(binds={DB1:db1_engine, DB2:db2_engine})


This raises an exception: sqlalchemy.exc.NoInspectionAvailable: No 
inspection system is available for object of type <class 
'sqlalchemy.ext.declarative.api.DeclarativeMeta'>


But when I keep the same class structure and switch back to the original 
bind, it works:


DBSession.configure(bind=db1_engine)


Of course, that means I'm back to using the monster database again. So 
what's wrong this?


DBSession.configure(binds={DB1:db1_engine, DB2:db2_engine})

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to