[Sqlalchemy-tickets] Issue #4295: Bundle w/ same name columns misbehaves (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2018-06-29 04:15:27
|
New issue 4295: Bundle w/ same name columns misbehaves https://bitbucket.org/zzzeek/sqlalchemy/issues/4295/bundle-w-same-name-columns-misbehaves Michael Bayer: ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declared_attr Base = declarative_base() class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True) data = Column(String) bs = relationship("B") class B(A): __tablename__ = 'b' id = Column(Integer, ForeignKey('a.id'), primary_key=True) class C(A): __tablename__ = 'c' c_id = Column(Integer, ForeignKey('a.id'), primary_key=True) from sqlalchemy.sql.elements import ClauseList # ClauseList / Bundle are equivalent print(ClauseList(A.id, C.c_id)) print(Bundle("pk", A.id, C.c_id).__clause_element__()) # w/ same name, they are not because it creates the clause list using *c without using exprs print(ClauseList(A.id, B.id)) print(Bundle("pk", A.id, B.id).__clause_element__()) ``` output: ``` #!python a.id, c.c_id a.id, c.c_id a.id, b.id b.id ``` fix: ``` #!diff diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 98747c680..0b6b32a07 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -1738,7 +1738,7 @@ class Query(object): self._group_by = False return - criterion = list(chain(*[_orm_columns(c) for c in criterion])) + criterion = c = list(chain(*[_orm_columns(c) for c in criterion])) criterion = self._adapt_col_list(criterion) if self._group_by is False: @@ -3964,7 +3964,7 @@ class Bundle(InspectionAttr): return cloned def __clause_element__(self): - return expression.ClauseList(group=False, *self.c) + return expression.ClauseList(group=False, *self.exprs) @property def clauses(self): ``` |