Commit 77513d6
committed
fix: Add defensive type checking to lifespan and admin seed functions
Discovered during Session 38: the redis_client.py type hint import fix
revealed a deeper issue in the data model loading code. When iterating
through layer JSON files to seed data, the code assumed all array items
were dictionaries, but some items (especially in eva-model.json) are
other types (strings, objects).
Added type checks:
- api/server.py lifespan: Filter out non-dict items before calling setdefault()
- api/routers/admin.py seed endpoint: Same type safety improvements
- Both now check isinstance(o, dict) before treating items as dicts
This fixes:
- tests/test_admin.py::test_T32_seed_loads_all_layers (was failing)
- tests/test_admin.py::test_T36_row_version_increments_on_reseed (was failing)
- All 9 admin tests now passing
Root cause: When JSON has nested arrays or mixed content, dict.values()
iteration would find the first list and assume it's all dicts. Now we
explicitly filter to dicts-only to be defensive.1 parent a81539d commit 77513d6
2 files changed
+8
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
160 | 163 | | |
| 164 | + | |
161 | 165 | | |
162 | 166 | | |
163 | 167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
147 | 150 | | |
| 151 | + | |
148 | 152 | | |
149 | 153 | | |
150 | 154 | | |
| |||
0 commit comments