Skip to content
Advertisement

Fastapi app: empty array or TypeError: Boolean value of this clause is not defined

So, Im doing simple todo-api app with fastapi and sqlmodel. Migrations went fine, but if I run my server, I dont see anything except empy array. I added some data in db file with DB Browser for SQLite, so it isn’t empty. And when I run my server and go to “/”, I see only empty array and no data, and if I go to “/1/”, I see this: TypeError: Boolean value of this clause is not defined

My main.py:

JavaScript

routers.py

JavaScript

repos:

JavaScript

models:

JavaScript

database.py file:

JavaScript

Traceback:

JavaScript

Advertisement

Answer

So, the exception is that you’re not actually executing the statement in select_todo before checking for error. In SqlModel statement is a special kind of object to build and process a query, so it can’t be directly checked for boolean value.

If you want to check if there are any results, place this statement under exec and check results instead.

There’s no sense to check the statement itself in if, it’s constructed successfully if no exception raised by that point

Advertisement