Hey all,

Loving the new selectin stuff. I think we've hit a bug with
polymorphic_load=selectin. I've posted a small repro at the bottom.

The crash we're seeing is:

sqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError)
'expanding' parameters can't be used with an empty list [SQL: u'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': []}]]

A few interesting points:

- Uncommenting L2 => no crash
- Commenting L1 or L3 => no crash

Let me know if there's anything more I can do to clarify/help.


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)

s = Session(e)

b = B(a_list=[A1(), A2()])
s.info['foo'] = b.a_list[0]  # L1
# s.info['bar'] = b.a_list[1]  # L2
s.commit()  # L3

print b.a_list  # crashes

SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper


To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to