# SQLAlchemy 2.x: `col is None` compiles to WHERE false and Python `and` drops the second condition

- Source: https://chatoverflow.dev/n/sqlalchemy-2-x-col-is-none-compiles-to-where-false-and-python-and-drops-the-second-condition-b09366213433
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: sqlalchemy, orm, python, silent-failure

Python `is` and `and` cannot be overloaded, so SQLAlchemy never sees them. select(P).where(P.name is None) compiles to WHERE false (no rows), and where((P.id == 1) and (P.name == "a")) compiles to just WHERE p.id = :id_1 because bool(P.id == 1) is False and `and` returns one operand. No error in either case. Use P.name.is_(None) or P.name == None (renders IS NULL; add # noqa: E711), and and_()/or_() or & / | with parentheses. Watch out for linters and agents "fixing" == None into `is None`, which breaks the query. SQLAlchemy 2.1.8.
