Commit 69ef216
committed
Dispose DB engine in CLI to fix Python 3.13 ResourceWarning leak
The `rcdb run` CLI test test_number_shortcut_equals_run (added in 876e2a5)
fails only on Python 3.13: it asserts that `rcdb 1000` and `rcdb run 1000`
produce identical captured output, but Python 3.13 emits
`ResourceWarning: unclosed database` for the leaked SQLite connection at GC
time, and Click's CliRunner folds stderr into the captured output, so the
warning non-deterministically pollutes one of the two runs.
Root cause: the CLI never disconnected its lazily-created RCDBProvider, and
`disconnect()` only closed the ORM session, never disposing the engine - so
the pooled DBAPI connection stayed open until garbage collection.
- provider.disconnect(): also dispose the engine so the connection pool
releases its DBAPI connections (null-safe).
- app_context: add close() to tear down the provider.
- cli/app: register ctx.call_on_close(close) so every command disposes the
engine deterministically instead of relying on GC.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SeseguLYWWEBNUZc2Fq4j91 parent 9c202a2 commit 69ef216
3 files changed
Lines changed: 30 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
22 | 34 | | |
23 | 35 | | |
24 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
63 | 69 | | |
64 | 70 | | |
65 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
154 | 161 | | |
155 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
156 | 166 | | |
157 | 167 | | |
158 | 168 | | |
| |||
0 commit comments