Skip to content
Advertisement

AttributeError while querying: Neither ‘InstrumentedAttribute’ object nor ‘Comparator’ has an attribute

The following code:

JavaScript

is giving me this error:

JavaScript

Any explanations, as to why this is happening, and guidance to how such a thing could be achieved?

Advertisement

Answer

This is because you are trying to access bar from the FooBar class rather than a FooBar instance. The FooBar class does not have any bar objects associated with it–bar is just an sqlalchemy InstrumentedAttribute. This is why you get the error:

JavaScript

You will get the same error by typing FooBar.bar.foo.name outside the sqlalchemy query.

The solution is to call the Foo class directly:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement