Commit 423ee59
fix(pkm): A31 — read-only commands tolerate a behind-schema DB (degraded column)
Found by real-install testing of pkm 0.2.0 on .227: A25 added the `degraded`
column with an ALTER-TABLE migration, but migrations run only on a read-WRITE
open. The read-only (immutable=1) open used by non-root readers — and by root
via a read-only subcommand — returns before migrating, so on a system upgraded
from a pre-A25 pkm every read command hitting list_installed crashed with
`sqlite3.OperationalError: no such column: degraded` until some later root
command happened to run the migration. The unit suite never caught it because it
always builds a fresh, fully-migrated DB; only a real upgrade path exposes it —
exactly what step-1 real-install testing is for.
Fix: list_installed selects schema-tolerantly. Columns are introspected once at
open (_table_columns -> self._installed_cols, on BOTH the read-only and the
read-write paths), and a new _col() helper emits `NULL AS <col>` for any column
absent on an un-migrated read-only DB instead of naming it directly — so reads
degrade gracefully (degraded -> None = healthy) regardless of migration timing.
Reuse this pattern for any future migration-added column read on the read path.
tests/pkm/test_pkm_a31_schema_tolerant.py: old-schema DB (no degraded) opened
read-only + list_installed no-crash, tier filter, and full-schema round-trip.
Full pkm suite 323 passed; audit registry 30/30 (A31 added + verified). Folded
into the unreleased pkm 0.2.0 (no version change — 0.2.0 has not shipped).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>1 parent a297936 commit 423ee59
3 files changed
Lines changed: 139 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
199 | 205 | | |
200 | 206 | | |
201 | 207 | | |
| |||
214 | 220 | | |
215 | 221 | | |
216 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
217 | 244 | | |
218 | 245 | | |
219 | 246 | | |
| |||
328 | 355 | | |
329 | 356 | | |
330 | 357 | | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
331 | 364 | | |
332 | 365 | | |
333 | | - | |
334 | | - | |
335 | | - | |
| 366 | + | |
336 | 367 | | |
337 | 368 | | |
338 | 369 | | |
339 | 370 | | |
340 | | - | |
341 | | - | |
342 | | - | |
| 371 | + | |
343 | 372 | | |
344 | 373 | | |
345 | 374 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
436 | 436 | | |
437 | 437 | | |
438 | 438 | | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
0 commit comments