polymorphic aliasing failure when using trivial column subclass

Issue #2918 resolved
Mike Bayer repo owner created an issue

this seems like an 0.9 regression

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)

class MySpecialColumn(Column):
    pass


class B(A):
    __tablename__ = 'b'

    id = Column(ForeignKey('a.id'), primary_key=True)
    x = MySpecialColumn(String)

s = Session()

print s.query(A).join(B).filter(B.x == 'asdf')

Comments (3)

  1. Mike Bayer reporter

    it's annotations, here's a test case:

    from sqlalchemy import Column
    
    class MySpecialColumn(Column):
        pass
    
    
    col = MySpecialColumn('x', String)
    binary_1 = col == 5   # caches col.comparator, col.comparator.expr == col
    c2 = col._annotate({"x": "foo"})   # uses Annotated, not AnnotatedColumn, as base class
    binary_2 = c2 == 5   # fails to use a new col.comparator, uses the old one with col and missing annotations
    assert binary_2.left._annotations == {"x": "foo"}
    
  2. Log in to comment