UnboundExecutionError for joint table subclasses when binds is constructed from list of tables
Issue #3202
duplicate
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:
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?
Comments (3)
-
repo owner -
repo owner - changed status to duplicate
Duplicate of
#3035. -
repo owner this is working in latest master
- Log in to comment
related is
#1416and#3035but for this.#3035should resolve