descriptive error message when attempting to repurpose an instrumented attribute
See original GitHub issueMigrated issue, originally created by Mehdi GMIRA (@mehdigmira)
Hey,
Here is the test case:
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:
AttributeError: 'Myclass' object has no attribute '_sa_instance_state'
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
WMI Error Constants (WbemCli.h) - Win32 apps
If an error occurs, WMI returns an error code as an HRESULT value. These codes may be returned by scripts, C++ applications, or...
Read more >TypedArray - Android Developers
Be sure to call recycle() when done with them. ... If the attribute is not a float or an integer, this method will...
Read more >Database Error Messages - Oracle Help Center
Cause: An error was returned by the Oracle Registry service when attempting to create an. ACFS key. This message is accompanied by other...
Read more >Troubleshooting Geo - GitLab Docs
Here is a list of steps you should take to attempt to fix problem: Perform basic troubleshooting. Fix any PostgreSQL database replication errors....
Read more >Using SystemVerilog Assertions in RTL Code
SystemVerilog is a set of extensions to the Verilog hardware description language ... then the assertion fails and the simulator writes an error...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
hey there -
there’s an existing exception that does the messaging automatically. In a case like this we simply need to raise sqlalchemy.orm.exc.UnmappedInstanceError(instance), taking into account we want to use util.raise_() so that the “cause” can be linked, and the messaging is already there.
RamonWill has proposed a fix for this issue in the master branch:
Raise UnmappedInstanceError if the attribute of a database object is an unmapped object. https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2119