[Sqlalchemy-tickets] Issue #3202: UnboundExecutionError for joint table subclasses when binds is co
Brought to you by:
zzzeek
|
From: ods <iss...@bi...> - 2014-09-17 12:05:56
|
New issue 3202: UnboundExecutionError for joint table subclasses when binds is constructed from list of tables https://bitbucket.org/zzzeek/sqlalchemy/issue/3202/unboundexecutionerror-for-joint-table ods: The list of tables is the only list of mapped data that automatically collected in `MetaData` object. So it's the simplest way to construct session with multiple connections where separate connection is used for each metadata. `Session.get_bind()` does look up based on `mapper.mapped_table`. This works for simple mapped classes, but doesn't work for classes mapped to join like subclasses with joined table inheritance. Test case: ```python from sqlalchemy import Column, Integer, ForeignKey, create_engine, orm from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class A(Base): __tablename__ = 'A' id = Column(Integer, primary_key=True) type = Column(Integer, nullable=False) __mapper_args__ = {'polymorphic_on': type} class B(A): __tablename__ = 'B' id = Column(ForeignKey(A.id), primary_key=True) __mapper_args__ = {'polymorphic_identity': 1} engine = create_engine('sqlite://') binds = {table: engine for table in Base.metadata.sorted_tables} db = orm.sessionmaker(binds=binds)() print db.get_bind(A) # Engine(sqlite://) print db.get_bind(B) # sqlalchemy.exc.UnboundExecutionError: Could not locate a bind configured on mapper Mapper|B|B or this Session ``` Should we iterate through tables used in `Join` object `mapper.mapped_table` refers to? |