question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

descriptive error message when attempting to repurpose an instrumented attribute

See original GitHub issue

Migrated 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:closed
  • Created 7 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
zzzeekcommented, Jul 25, 2020

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.

0reactions
sqla-testercommented, Aug 13, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found