[Sqlalchemy-tickets] Issue #3858: object has no attribute '_sa_instance_state' (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: Mehdi G. <iss...@bi...> - 2016-11-21 09:37:32
|
New issue 3858: object has no attribute '_sa_instance_state' https://bitbucket.org/zzzeek/sqlalchemy/issues/3858/object-has-no-attribute-_sa_instance_state Mehdi GMIRA: Hey, I don't know if this a bug or something that I should expect this behaviour from SA, but I still find it very weird. Here is the test case: ```python from sqlalchemy import Column, DateTime, String, Integer, ForeignKey, func, Table, create_engine from sqlalchemy.orm import relationship, backref, sessionmaker, joinedload, contains_eager from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() engine = create_engine('sqlite://', echo=False) class Student(Base): __tablename__ = 'student' id = Column(Integer, primary_key=True) name = Column(String) Base.metadata.drop_all(engine) Base.metadata.create_all(engine) Session = sessionmaker(engine) session = Session() session.add(Student(name='foo')) session.commit() class Myclass(object): column = Student.name def test(self): print session.query(Student.id, Student.name).filter(self.__class__.column == 'foo').all() # does not raise print session.query(Student.id, Student.name).filter(self.column == 'foo').all() # raises error my_class = Myclass() my_class.test() ``` The error that is raised is: ```python AttributeError: 'Myclass' object has no attribute '_sa_instance_state' ``` |