[Sqlalchemy-tickets] Issue #3657: positional result column logic failing (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: Mike B. <iss...@bi...> - 2016-02-20 05:28:02
|
New issue 3657: positional result column logic failing https://bitbucket.org/zzzeek/sqlalchemy/issues/3657/positional-result-column-logic-failing Mike Bayer: Havent fully tracked this down yet, suspect the query wrapping in mssql for LIMIT/OFFSET is causing this to happen. very heisenbuggy, set PYTHONHASHEED=random and run lots of times against mssql: ``` #!python import sqlalchemy as sa import sqlalchemy.orm as saorm from sqlalchemy.ext.declarative import declarative_base #engine = sa.create_engine('mssql+pymssql://badams:password@192.168.56.101:1443/testdb', echo=True) engine = sa.create_engine('mssql+pymssql://scott:tiger@192.168.122.232:1213/test', echo=True) session = saorm.sessionmaker(bind=engine)() Base = declarative_base() class Person(Base): __tablename__ = 'people' id = sa.Column(sa.Integer, primary_key=True) name = sa.Column(sa.String) Base.metadata.create_all(engine) session.query(Person).delete() session.add(Person(name='foo')) session.add(Person(name='bar')) session.commit() results = session.query( Person.name.label('person'), ).add_entity( Person ).order_by( Person.name ) print results.count() print results.limit(1).offset(1).all() ``` the stack is a lie; to really make this fail we have to raise here (and this is another issue for 1.1, why aren't we raising here? ) ``` #!diff --- a/lib/sqlalchemy/engine/result.py +++ b/lib/sqlalchemy/engine/result.py @@ -420,7 +427,8 @@ class ResultMetaData(object): if key in self._keymap: processor, obj, index = self._keymap[key] else: - ret = self._key_fallback(key, False) + # MARKMARK + ret = self._key_fallback(key) #, False) if ret is None: return None processor, obj, index = ret ``` so ultimately the compiler._result_columns is wrong. on a bad run its: ``` #!python [ ('person', 'person', (Column('name', String(), table=<people>), 'person', 'person'), String()), ('people_id', 'people_id', (Column('id', Integer(), table=<people>, primary_key=True, nullable=False), 'people_id', 'people_id'), Integer()), ('people_name', 'people_name', (Column('name', String(), table=<people>), 'people_name', 'people_name'), String()) ] ``` on a good run it's: ``` #!python [ ('person', 'person', (<sqlalchemy.sql.elements.Label object at 0x7f46cc3dcf10>, 'person', 'person'), String()), ('people_id', 'people_id', (Column('id', Integer(), table=<people>, primary_key=True, nullable=False), 'people_id', 'people_id'), Integer()), ('people_name', 'people_name', (Column('name', String(), table=<people>), 'people_name', 'people_name'), String()) ] ``` so our label is occasionally getting whacked from the result list, and its a dictionary ordering issue. the LIMIT wrapping in mssql/base.py -> visit_select seems like it may be significant also. |