From 4d5d12d710dec1a960b775f2eb8b0cf2c212197b Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Tue, 3 Mar 2026 15:32:52 -0600 Subject: [PATCH] store: Fix: Peewee boolean filter always-truthy column reference --- ...r-always-truthy-column-reference-cd43d0.md | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 graph/fixes/fix-peewee-boolean-filter-always-truthy-column-reference-cd43d0.md diff --git a/graph/fixes/fix-peewee-boolean-filter-always-truthy-column-reference-cd43d0.md b/graph/fixes/fix-peewee-boolean-filter-always-truthy-column-reference-cd43d0.md new file mode 100644 index 00000000000..30e2884763a --- /dev/null +++ b/graph/fixes/fix-peewee-boolean-filter-always-truthy-column-reference-cd43d0.md @@ -0,0 +1,45 @@ +--- +id: cd43d051-d2e8-436e-b964-f9260739cc15 +type: fix +title: "Fix: Peewee boolean filter always-truthy column reference" +tags: [paper-dynasty-database, peewee, python, fastapi, boolean-filter, orm, bug] +importance: 0.6 +confidence: 0.8 +created: "2026-03-03T21:32:52.436667+00:00" +updated: "2026-03-03T21:32:52.436667+00:00" +--- + +## Problem + +`get_teams` endpoint in `app/routers_v2/teams.py` accepted `is_ai: bool | None` query param but always filtered for AI teams regardless of value. + +## Root Cause + +```python +if is_ai is not None: + all_teams = all_teams.where(Team.is_ai) # always truthy — column reference +``` + +`Team.is_ai` in a Peewee `.where()` call is a column expression that evaluates as truthy, not as `== True`. Passing `is_ai=False` still filtered for AI teams. + +## Solution + +Use explicit boolean comparison, same as adjacent `has_guide` filter: + +```python +if is_ai is not None: + if not is_ai: + all_teams = all_teams.where(Team.is_ai == False) + else: + all_teams = all_teams.where(Team.is_ai == True) +``` + +This is also PostgreSQL-compatible (ORM generates proper `= false` / `= true` SQL). + +## Files Changed + +- `app/routers_v2/teams.py` lines 152–156 + +## Pattern + +In Peewee ORM, always use `Model.bool_field == False` / `== True` for boolean filters. Never use bare `Model.bool_field` inside `.where()` to represent `True` — it works by accident but breaks for `False`.