store: Fix: Peewee boolean filter always-truthy column reference
This commit is contained in:
parent
23cf74777a
commit
4d5d12d710
@ -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`.
|
||||||
Loading…
Reference in New Issue
Block a user