adaptation within query.join() etc. being weird for column prop against instrumented col

Issue #2316 resolved
Mike Bayer repo owner created an issue

the column_property expression fails to get adapted

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base= declarative_base()


class A(Base):
    __tablename__ = "a"
    id      = Column(Integer, primary_key=True)
    type    = Column(String(40), nullable=False)
    __mapper_args__ = {'polymorphic_on': type}

    # works
    # anything = column_property(id + 1000)

# works
# A.anything = column_property(A.__table__.c.id + 1000)

# fails
A.anything = column_property(A.id + 1000)

class B(A):
    __tablename__ = "b"
    account_id      = Column(Integer, ForeignKey('a.id'), primary_key=True)
    x_id            = Column(Integer, ForeignKey('x.id'), nullable=False)
    __mapper_args__ = {'polymorphic_identity': 'named'}

class X(Base):
    __tablename__ = "x"
    id = Column(Integer, primary_key=True)
    b = relationship("B")

s = Session()

# joins:

print s.query(X, B).join("b")

# or joinedload()

print s.query(X).options(joinedload("b"))

# or subqueryload()

Comments (3)

  1. Mike Bayer reporter

    and here's the fix !

    diff -r b746921e78f3890f643ed6581ac01b25f673b476 lib/sqlalchemy/orm/properties.py
    --- a/lib/sqlalchemy/orm/properties.py  Wed Nov 02 12:34:55 2011 -0400
    +++ b/lib/sqlalchemy/orm/properties.py  Sun Nov 06 09:33:42 2011 -0800
    @@ -60,7 +60,7 @@
             :param extension:
    
             """
    -        self.columns = [for c in columns](expression._labeled(c))
    +        self.columns = [for c in columns](expression._labeled(_orm_deannotate(c)))
             self.group = kwargs.pop('group', None)
             self.deferred = kwargs.pop('deferred', False)
             self.instrument = kwargs.pop('_instrument', True)
    
  2. Mike Bayer reporter

    that was much, much harder than anticipated, as the deannotation was tripping off the "froms already generated" thing. Removed that whole check as well as the caching of _froms, the complexity here is not worth it and there's no real performance hit for the vast majority of usages. 699146086df8fd8778582a03267f8f28c5cdad7a

  3. Log in to comment