Great, thanks! On Mon, 19 Dec 2016 12:43:26 -0500 mike bayer <[email protected]> wrote:
> thanks, this is > https://bitbucket.org/zzzeek/sqlalchemy/issues/3874/bundle-does-not-provide-entities-fails-on > > and the gerrit should merge today. > > > > On 12/19/2016 11:58 AM, Michael Williamson wrote: > > Hello! > > > > When selecting from a polymorphic table using a bundle, the query > > seems to drop the condition on the discriminator. For instance, > > suppose we have an Employee class that has a name column, with > > subclasses Manager and Engineer. When I query for Manager.name, I > > get back the names of just the managers. When I query for > > Manager.name as part of a bundle, I get back the names of both > > managers and engineers. Looking at the SQL, the latter query is > > missing the WHERE clause for the discriminator altogether. > > > > Full example with output below. Any pointers on whether this is a > > bug or I'm doing something wrong/weird would be appreciated. > > > > Thanks > > > > Michael > > > > from sqlalchemy import * > > from sqlalchemy.orm import * > > from sqlalchemy.ext.declarative import declarative_base > > > > Base = declarative_base() > > > > > > class Employee(Base): > > __tablename__ = 'employee' > > id = Column(Integer, primary_key=True) > > type = Column(String(50)) > > name = Column(String(30)) > > > > __mapper_args__ = { > > 'polymorphic_identity': 'employee', > > 'polymorphic_on': type, > > 'with_polymorphic': '*' > > } > > > > > > class Engineer(Employee): > > __mapper_args__ = { > > 'polymorphic_identity': 'engineer', > > } > > > > > > class Manager(Employee): > > __mapper_args__ = { > > 'polymorphic_identity': 'manager', > > } > > > > > > e = create_engine("sqlite://", echo=True) > > Base.metadata.create_all(e) > > > > s = Session(e) > > s.add_all([ > > Engineer(name='e1'), > > Engineer(name='e2'), > > Manager(name='m1'), > > ]) > > > > s.commit() > > > > print(s.query(Manager.name).select_from(Manager).all()) > > print(s.query(Bundle("name", > > Manager.name)).select_from(Manager).all()) > > > > Output: > > > > 2016-12-19 16:48:39,502 INFO sqlalchemy.engine.base.Engine > > SELECT employee.name AS employee_name FROM employee > > WHERE employee.type IN (?) > > 2016-12-19 16:48:39,502 INFO sqlalchemy.engine.base.Engine > > ('manager',) [(u'm1',)] > > 2016-12-19 16:48:39,503 INFO sqlalchemy.engine.base.Engine > > SELECT employee.name AS employee_name FROM employee > > 2016-12-19 16:48:39,503 INFO sqlalchemy.engine.base.Engine () > > [((u'e1',),), ((u'e2',),), ((u'm1',),)] > > > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
