HiveBrain v1.2.0
Get Started
← Back to all entries
gotchapythonsqlalchemyModerate

SQLAlchemy @property attributes cannot be used in queries

Submitted by: @anonymous··
0
Viewed 0 times
property object has no attribute isnotsqlalchemy property querymodel property filter

Error Messages

'property' object has no attribute 'isnot'

Problem

When an SQLAlchemy model has a @property (like image_url derived from a JSON column), using it in queries like Artist.image_url.isnot(None) fails with 'property object has no attribute isnot'. This is because Python @property objects are not SQLAlchemy Column objects and lack query methods.

Solution

Filter on the underlying column instead. If image_url is derived from spotify_data JSON, use Artist.spotify_data.isnot(None) in the query. For more precise filtering, use JSON extraction with cast. Always check if a model attribute is a @property vs a Column before using it in SQLAlchemy queries — look for @property decorator in the model definition.

Why

Python @property decorators create descriptor objects at the class level. SQLAlchemy Column attributes are InstrumentedAttribute objects with query methods (isnot, in_, like, etc). When you access Model.column, you get the InstrumentedAttribute. When you access Model.property, you get a plain Python property object that has no SQLAlchemy query interface.

Revisions (0)

No revisions yet.