The test database that lied · figure 1

One statement, two dialects

The same SQLAlchemy statement leaves with_for_update_if_supported as two different queries — and only one of them ever ran in CI.

or click either path
select(func.count()).where(owner_filter) one SQLAlchemy statement
with_for_update_if_supported which dialect?
testsqlite+aiosqlite:///:memory:

helper early-returns the bare statement

SELECT count(*) … no lock — _for_update_arg = None
✓ tests pass
productionPostgreSQL via asyncpg

helper attaches the lock

SELECT count(*) … FOR UPDATE OF workspaces
FeatureNotSupportedError “FOR UPDATE is not allowed with aggregate function” → HTTP 500
The clause that crashed production was never constructed in test. The suite didn’t run the broken query leniently — it ran a different, correct query.