Relative Content

Tag Archive for pythonsqlsqlalchemyfastapi

SQLAlchemy ObjectNotExecutableError when querying by ID with raw SQL after Python update

I’m developing a FastAPI application and using SQLAlchemy to interact with a MySQL database. I have a route to fetch a post by its ID, but I’m encountering an ObjectNotExecutableError when executing the query. Everything was working fine before I updated my Python, but now I’m forced to use the text function and I’m encountering issues.
The error I get after using text is pydantic_core.ValidationError. Here’s the relevant part of my code with text in line 5: