[Sqlalchemy-tickets] Issue #4199: selectin polymorphic hitting expanding in w/ no entries (zzzeek/s
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2018-02-23 18:40:31
|
New issue 4199: selectin polymorphic hitting expanding in w/ no entries https://bitbucket.org/zzzeek/sqlalchemy/issues/4199/selectin-polymorphic-hitting-expanding-in Michael Bayer: ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import event Base = declarative_base() class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True) type = Column(String) b_id = Column(ForeignKey('b.id')) __mapper_args__ = { 'polymorphic_on': type, } class A1(A): __tablename__ = 'a1' id = Column(Integer, ForeignKey('a.id'), primary_key=True) __mapper_args__ = { 'polymorphic_identity': 'a1', 'polymorphic_load': 'selectin', } class A2(A): __tablename__ = 'a2' id = Column(Integer, ForeignKey('a.id'), primary_key=True) __mapper_args__ = { 'polymorphic_identity': 'a2', 'polymorphic_load': 'selectin', } class B(Base): __tablename__ = 'b' id = Column(Integer, primary_key=True) a_list = relationship('A') e = create_engine("sqlite://", echo=True) Base.metadata.create_all(e) s = Session(e) b = B(a_list=[A1(), A2()]) s.add(b) x = b.a_list[0] # uncomment for pass #y = b.a_list[1] s.commit() # L3 print(b.a_list) # crashes ``` ``` #!python File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/engine/default.py", line 736, in _expand_in_parameters "'expanding' parameters can't be used with an " sqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError) 'expanding' parameters can't be used with an empty list [SQL: 'SELECT a1.id AS a1_id, a.id AS a_id, a.type AS a_type \nFROM a JOIN a1 ON a.id = a1.id \nWHERE a.id IN ([EXPANDING_primary_keys]) ORDER BY a.id'] [parameters: [{'primary_keys': []}]] ``` |