[Sqlalchemy-tickets] Issue #4373: Load.load_only on polymorphic child doesn't work (zzzeek/sqlalche
Brought to you by:
zzzeek
From: Dmytro S. <iss...@bi...> - 2018-11-23 16:07:07
|
New issue 4373: Load.load_only on polymorphic child doesn't work https://bitbucket.org/zzzeek/sqlalchemy/issues/4373/loadload_only-on-polymorphic-child-doesnt Dmytro Starosud: This is using SQLAlchemy==1.2.14. Please consider following code snippet: ``` #!python from sqlalchemy import Column, Integer, String, create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import Load, Query from sqlalchemy.pool import NullPool engine = create_engine('postgresql://***', poolclass=NullPool) connection = engine.connect() connection.begin_nested() Base = declarative_base() class MyEntity(Base): __tablename__ = 'my_entity' id = Column(Integer, primary_key=True) a = Column(String, nullable=False) b = Column(String, nullable=False) kind = Column(String, nullable=False) __mapper_args__ = {'polymorphic_on': kind} Base.metadata.create_all(connection) class MyChild(MyEntity): __mapper_args__ = {'polymorphic_identity': 'child_1'} print(MyEntity) print(Query(MyEntity).options(Load(MyEntity).load_only('a'))) print(MyChild) print(Query(MyChild).options(Load(MyChild).load_only('a'))) ``` It produces following output: ``` <class '__main__.MyEntity'> SELECT my_entity.id AS my_entity_id, my_entity.a AS my_entity_a, my_entity.kind AS my_entity_kind FROM my_entity <class '__main__.MyChild'> SELECT my_entity.id AS my_entity_id, my_entity.a AS my_entity_a, my_entity.b AS my_entity_b, my_entity.kind AS my_entity_kind FROM my_entity WHERE my_entity.kind IN (:kind_1) ``` Please assist. Did I misread documentation? Note unbound `load_only('a')` works well. |