Query.__str__ calls nonexisting method, raises AttributeError

Issue #1066 resolved
Former user created an issue

Printing Query object raises: <type 'exceptions.AttributeError'>: 'Query' object has no attribute 'compile'.

Log says that in r4775 Query.compile method got removed, but Query.str() still calls it (at least in trunk r4826).

I guess that change self.compile() to self.statement should to do the job.

  • andrija@gmail.com

Comments (5)

  1. Former user Account Deleted
    $ cat boom.py 
    from sqlalchemy import *
    from sqlalchemy.orm import *
    
    metadata = MetaData(create_engine('sqlite:///'))
    foo = Table('foo', metadata, Column('id', Integer, primary_key=True))
    metadata.create_all()
    class Foo(object):
        pass
    mapper(Foo, foo)
    session = create_session()
    q = session.query(Foo).filter_by(id=1)
    
    print q #boom!
    
    $ python boom.py 
    Traceback (most recent call last):
      File "boom.py", line 13, in <module>
        print q #boom!
      File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta1dev_r4854-py2.5.egg/sqlalchemy/orm/query.py", line 1448, in __str__
        return str(self.compile())
    AttributeError: 'Query' object has no attribute 'compile'
    

    With patch:

    $ python boom.py 
    SELECT foo.id 
    FROM foo 
    WHERE foo.id = ?
    

    –AlexB

  2. Log in to comment