Checking for None
occurs often enough that you need to know this little tip.
The SQL
To build this SQL Statement:
|
|
Not How To Write It
You shouldn’t declare your SQLAlchemy query as follows:
|
|
It feels natural if you have written Python code before, but it won’t work.
Correct Syntax
Instead, use SqlAlchemy like this, using ==
operator :
|
|
Why
Because SQLAlchemy uses magic methods (or operator overloading) to create SQL
constructs, it can only handle operators such as !=
or ==
, but isn’t able to work with is
(which is a very valid Python construct).
Source: Stackoverflow
Follow me
Thanks for reading this article. Make sure to follow me on X, subscribe to my Substack publication and bookmark my blog to read more in the future.
Photo by Pixabay