dbkit-sql 0.3.0__tar.gz → 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/CHANGELOG.md +27 -0
  2. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/PKG-INFO +2 -2
  3. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/pyproject.toml +1 -1
  4. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/__init__.py +1 -1
  5. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_async/_compat.py +26 -0
  6. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_async/engine.py +5 -3
  7. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_async/executor.py +8 -1
  8. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_async/transaction.py +12 -3
  9. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_core/config.py +7 -0
  10. dbkit_sql-0.3.1/src/dbkit/_core/errors/redaction.py +151 -0
  11. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_sync/_compat.py +15 -0
  12. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_sync/engine.py +5 -3
  13. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_sync/executor.py +8 -1
  14. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_sync/transaction.py +12 -3
  15. dbkit_sql-0.3.1/tests/integration/test_commit_interruption.py +74 -0
  16. dbkit_sql-0.3.1/tests/security/test_redaction.py +301 -0
  17. dbkit_sql-0.3.1/tests/unit/test_commit_cancellation.py +351 -0
  18. dbkit_sql-0.3.0/src/dbkit/_core/errors/redaction.py +0 -96
  19. dbkit_sql-0.3.0/tests/security/test_redaction.py +0 -85
  20. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
  21. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  22. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
  23. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  24. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/.github/dependabot.yml +0 -0
  25. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/.github/workflows/ci.yml +0 -0
  26. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/.github/workflows/dependency-matrix.yml +0 -0
  27. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/.github/workflows/docs.yml +0 -0
  28. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/.github/workflows/release.yml +0 -0
  29. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/.github/workflows/security.yml +0 -0
  30. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/.gitignore +0 -0
  31. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/CONTRIBUTING.md +0 -0
  32. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/LICENSE +0 -0
  33. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/Makefile +0 -0
  34. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/README.md +0 -0
  35. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/SECURITY.md +0 -0
  36. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/__init__.py +0 -0
  37. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/__main__.py +0 -0
  38. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/_common.py +0 -0
  39. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/_results.py +0 -0
  40. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/_stats.py +0 -0
  41. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/bench_batch.py +0 -0
  42. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/bench_batch_collector.py +0 -0
  43. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/bench_concurrency_scaling.py +0 -0
  44. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/bench_crud.py +0 -0
  45. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/bench_latency.py +0 -0
  46. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/bench_observability_overhead.py +0 -0
  47. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/bench_overhead.py +0 -0
  48. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/bench_pgbouncer_compatible.py +0 -0
  49. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/bench_pool_exhaustion.py +0 -0
  50. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/bench_shard_cardinality.py +0 -0
  51. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/bench_streaming_scale.py +0 -0
  52. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/bench_throughput.py +0 -0
  53. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/bench_unnest.py +0 -0
  54. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/check_regression.py +0 -0
  55. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/benchmarks/soak.py +0 -0
  56. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docker-compose.yml +0 -0
  57. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/api/config.md +0 -0
  58. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/api/database.md +0 -0
  59. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/api/errors.md +0 -0
  60. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/api/integrations.md +0 -0
  61. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/api/observability.md +0 -0
  62. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/api/query.md +0 -0
  63. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/assets/logo.svg +0 -0
  64. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/cli.md +0 -0
  65. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/dynamic-registration.md +0 -0
  66. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/index.md +0 -0
  67. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/observability.md +0 -0
  68. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/requirements.md +0 -0
  69. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/roadmap.md +0 -0
  70. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/security.md +0 -0
  71. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/testing.md +0 -0
  72. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/troubleshooting.md +0 -0
  73. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/docs/versioning.md +0 -0
  74. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/advisory_locks.py +0 -0
  75. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/batch_collector.py +0 -0
  76. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/bulk_insert_upsert.py +0 -0
  77. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/copy_ingest.py +0 -0
  78. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/error_handling.py +0 -0
  79. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/health_and_pool.py +0 -0
  80. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/inbox_idempotent_consumer.py +0 -0
  81. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/opentelemetry_observability.py +0 -0
  82. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/pgbouncer_mode.py +0 -0
  83. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/pipeline_mode.py +0 -0
  84. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/quickstart_async.py +0 -0
  85. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/quickstart_sync.py +0 -0
  86. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/retries_and_circuit_breaker.py +0 -0
  87. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/run_all.py +0 -0
  88. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/streaming.py +0 -0
  89. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/streaming_checkpoint_resume.py +0 -0
  90. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/sync_feature_parity.py +0 -0
  91. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/transactional_outbox.py +0 -0
  92. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/examples/transactions_savepoints.py +0 -0
  93. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/mkdocs.yml +0 -0
  94. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_async/__init__.py +0 -0
  95. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_async/connection.py +0 -0
  96. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_async/database.py +0 -0
  97. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_async/health.py +0 -0
  98. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_async/resilience.py +0 -0
  99. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_async/streaming.py +0 -0
  100. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_core/__init__.py +0 -0
  101. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_core/bulk.py +0 -0
  102. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_core/circuit.py +0 -0
  103. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_core/errors/__init__.py +0 -0
  104. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_core/errors/base.py +0 -0
  105. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_core/errors/classifier.py +0 -0
  106. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_core/errors/sqlstate.py +0 -0
  107. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_core/idempotency_lint.py +0 -0
  108. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_core/keys.py +0 -0
  109. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_core/policies.py +0 -0
  110. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_core/query.py +0 -0
  111. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_core/result.py +0 -0
  112. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_core/routing.py +0 -0
  113. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_pool.py +0 -0
  114. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_sync/__init__.py +0 -0
  115. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_sync/connection.py +0 -0
  116. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_sync/database.py +0 -0
  117. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_sync/health.py +0 -0
  118. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_sync/resilience.py +0 -0
  119. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/_sync/streaming.py +0 -0
  120. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/cli/__init__.py +0 -0
  121. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/cli/main.py +0 -0
  122. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/errors.py +0 -0
  123. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/integrations/__init__.py +0 -0
  124. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/integrations/batch.py +0 -0
  125. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/integrations/fastapi.py +0 -0
  126. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/integrations/inbox.py +0 -0
  127. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/integrations/outbox.py +0 -0
  128. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/observability/__init__.py +0 -0
  129. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/observability/logging.py +0 -0
  130. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/observability/metrics.py +0 -0
  131. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/observability/otel_metrics.py +0 -0
  132. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/observability/prometheus.py +0 -0
  133. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/observability/tracing.py +0 -0
  134. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/postgres/__init__.py +0 -0
  135. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/postgres/copy.py +0 -0
  136. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/postgres/pipeline.py +0 -0
  137. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/postgres/unnest.py +0 -0
  138. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/py.typed +0 -0
  139. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/src/dbkit/testing/__init__.py +0 -0
  140. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/__init__.py +0 -0
  141. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/conftest.py +0 -0
  142. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/integration/__init__.py +0 -0
  143. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/integration/_mp_budget_worker.py +0 -0
  144. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/integration/test_async_integration.py +0 -0
  145. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/integration/test_cli_integration.py +0 -0
  146. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/integration/test_multiprocess_connection_budget.py +0 -0
  147. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/integration/test_resilience_scenarios.py +0 -0
  148. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/integration/test_sharding_and_replicas.py +0 -0
  149. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/integration/test_sync_integration.py +0 -0
  150. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/integration/test_throughput_paths.py +0 -0
  151. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/property/__init__.py +0 -0
  152. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/property/test_invariants.py +0 -0
  153. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/security/__init__.py +0 -0
  154. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/security/test_sql_injection.py +0 -0
  155. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/__init__.py +0 -0
  156. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_benchmark_stats.py +0 -0
  157. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_bulk_batch.py +0 -0
  158. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_cancellation_shielding.py +0 -0
  159. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_circuit.py +0 -0
  160. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_cli.py +0 -0
  161. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_config.py +0 -0
  162. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_default_metrics_sink.py +0 -0
  163. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_dual_api.py +0 -0
  164. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_dynamic_registration.py +0 -0
  165. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_engine_registry.py +0 -0
  166. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_errors.py +0 -0
  167. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_fastapi_integration.py +0 -0
  168. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_idempotency_lint.py +0 -0
  169. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_integrations_outbox.py +0 -0
  170. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_logging.py +0 -0
  171. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_otel_metrics.py +0 -0
  172. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_policies.py +0 -0
  173. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_prometheus_metrics.py +0 -0
  174. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_query.py +0 -0
  175. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_query_settings.py +0 -0
  176. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_resilience.py +0 -0
  177. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_result.py +0 -0
  178. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_sharding_replica.py +0 -0
  179. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_testing_fakes.py +0 -0
  180. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_tracing.py +0 -0
  181. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_unasync_translation.py +0 -0
  182. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tests/unit/test_unnest.py +0 -0
  183. {dbkit_sql-0.3.0 → dbkit_sql-0.3.1}/tools/run_unasync.py +0 -0
@@ -6,6 +6,33 @@ All notable changes to this project are documented here. The format is based on
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.3.1] - 2026-11-21
10
+
11
+ ### Security
12
+ - **DSN passwords are redacted in every form** wherever a URL or driver message can reach a log, trace, metric
13
+ or error (§30): URL userinfo (including passwords containing `/`, `+`, `=` or spaces, the password-only
14
+ `scheme://:pw@host` form and percent-encoded passwords), URL query parameters whose decoded key contains
15
+ `password` (`?password=`, `?sslpassword=`, `?db_password=`, nested `?next=/x?password=`), libpq keyword DSNs
16
+ and other `password`-like keys (`password=`, `PGPASSWORD=`, `db_password: x`, quoted or not), and mapping or
17
+ JSON forms (`'password': 'x'`, `"password":"x"`). A value after a recognised key is redacted to its natural
18
+ end, so an unusual or very long value is hidden whole. `TargetConfig.__repr__` (and so the reprs of
19
+ `DatabaseConfig` and `DbkitConfig`) uses the same redaction; the URL itself is unchanged for the engine.
20
+ - **Redaction time is bounded** on long, attacker-influenced error text: search patterns are bounded and anchored,
21
+ and `sanitize_message` cuts messages to 8192 characters before redacting (a DSN password cut before its `@` is
22
+ redacted to the end), so no text past the cut reaches the output.
23
+ - **Engine-creation errors keep no driver error in their chain.** The error is raised outside the `except` block,
24
+ so a driver message that echoes the URL is not kept as `__context__` (sync and async).
25
+
26
+ ### Fixed
27
+ - **An interruption during COMMIT is never swallowed or reclassified** (task cancellation, `KeyboardInterrupt`,
28
+ `SystemExit`; §15): no rollback is attempted, the connection is invalidated inside a shield and never reused,
29
+ the outcome is counted as `commit_unknown`, and the interruption propagates unchanged. This covers explicit
30
+ transactions and the auto-commit scope behind `execute`, `execute_many`, `connection()` and best-effort bulk,
31
+ sync and async. A further cancellation or a failure while invalidating is added as a note on the original
32
+ exception (saying whether the invalidate finished); a `KeyboardInterrupt` or `SystemExit` raised while
33
+ invalidating outranks the original and propagates.
34
+ - A password-less URL followed by an unrelated `@` later in a message stays readable (`host:port/db`).
35
+
9
36
  ## [0.3.0] - 2026-07-21
10
37
 
11
38
  ### Added
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: dbkit-sql
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: A thin, high-throughput SQL toolkit over SQLAlchemy Core — sync and async, ORM-free.
5
5
  Project-URL: Homepage, https://github.com/talaatmagdyx/dbkit-sql
6
6
  Project-URL: Source, https://github.com/talaatmagdyx/dbkit-sql
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "dbkit-sql"
7
- version = "0.3.0"
7
+ version = "0.3.1"
8
8
  description = "A thin, high-throughput SQL toolkit over SQLAlchemy Core — sync and async, ORM-free."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -40,7 +40,7 @@ from ._core.routing import (
40
40
  )
41
41
  from ._sync.database import Database
42
42
 
43
- __version__ = "0.3.0"
43
+ __version__ = "0.3.1"
44
44
 
45
45
  __all__ = [
46
46
  "AsyncDatabase",
@@ -109,3 +109,29 @@ async def shield_from_cancellation(coro: Coroutine[Any, Any, T]) -> T:
109
109
  with contextlib.suppress(asyncio.CancelledError, Exception):
110
110
  await asyncio.shield(task)
111
111
  raise
112
+
113
+
114
+ async def invalidate_after_interrupted_commit(conn: Any, original: BaseException) -> None:
115
+ """Drop a connection whose COMMIT was interrupted (outcome unknown) from the pool, shielded.
116
+
117
+ A failure or a further cancellation while invalidating is noted on ``original`` (which the
118
+ caller re-raises), saying whether the invalidate finished, so it is never silently lost. (A
119
+ KeyboardInterrupt or SystemExit raised inside the shielded invalidate escapes through the event
120
+ loop, as asyncio does for those, rather than reaching this coroutine.)"""
121
+ finished = False
122
+
123
+ async def _invalidate() -> None:
124
+ nonlocal finished
125
+ await conn.invalidate()
126
+ finished = True
127
+
128
+ try:
129
+ await shield_from_cancellation(_invalidate())
130
+ except BaseException as second:
131
+ if not (isinstance(second, Exception) or is_cancellation(second)):
132
+ raise
133
+ state = "finished" if finished else "did not finish"
134
+ original.add_note(
135
+ f"dbkit: {type(second).__name__} while invalidating the connection; "
136
+ f"the invalidate {state}"
137
+ )
@@ -18,6 +18,7 @@ from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
18
18
 
19
19
  from .._core.config import DbkitConfig, PoolConfig, TargetConfig
20
20
  from .._core.errors import DatabaseConfigurationError, DatabaseRoutingError
21
+ from .._core.errors.redaction import sanitize_message
21
22
  from .._core.keys import EngineKey
22
23
  from .._core.routing import ResolvedRoute
23
24
  from .._pool import PoolInstrumentation, PoolSnapshot
@@ -136,9 +137,10 @@ class AsyncEngineRegistry:
136
137
  try:
137
138
  return create_async_engine(target.url, **kwargs)
138
139
  except Exception as exc:
139
- raise DatabaseConfigurationError(
140
- f"failed to create engine for {target.name!r}: {exc}"
141
- ) from exc
140
+ reason = sanitize_message(str(exc))
141
+ # Raised outside the except block, so the driver error (which can echo the URL, password
142
+ # included) is not even kept as __context__ (§30).
143
+ raise DatabaseConfigurationError(f"failed to create engine for {target.name!r}: {reason}")
142
144
 
143
145
  async def get(self, route: ResolvedRoute) -> EngineEntry:
144
146
  """The cached engine for ``route``, creating (and, if needed, evicting) one lazily."""
@@ -34,7 +34,7 @@ from ..observability import logging as obslog
34
34
  from ..observability import metrics as m
35
35
  from ..observability.metrics import MetricsSink
36
36
  from ..observability.tracing import Tracer
37
- from ._compat import API_LABEL
37
+ from ._compat import API_LABEL, invalidate_after_interrupted_commit
38
38
  from .connection import AsyncConnectionScope
39
39
  from .engine import AsyncEngineRegistry, EngineEntry
40
40
  from .resilience import ConcurrencyLimiter, run_with_retries
@@ -283,6 +283,13 @@ class ResilientExecutor:
283
283
  try:
284
284
  await conn.commit()
285
285
  except BaseException as commit_exc:
286
+ if not isinstance(commit_exc, Exception):
287
+ # Interrupted during COMMIT (cancellation, KeyboardInterrupt,
288
+ # SystemExit): the outcome is unknown. No rollback; the connection is
289
+ # invalidated, never reused; the interruption propagates unchanged.
290
+ self._metrics.incr(m.COMMIT_UNKNOWN, labels=labels) # counted first
291
+ await invalidate_after_interrupted_commit(conn, commit_exc)
292
+ raise commit_exc
286
293
  # Mirror _AsyncTransactionManager._commit(): a failure during COMMIT
287
294
  # may mean the write committed anyway (§15) — never silently swallow
288
295
  # that ambiguity, and never leave the exception unclassified either
@@ -25,7 +25,7 @@ from .._core.errors import (
25
25
  from ..observability import logging as obslog
26
26
  from ..observability import metrics as m
27
27
  from ..observability.metrics import MetricsSink, NoopMetrics
28
- from ._compat import is_cancellation, shield_from_cancellation
28
+ from ._compat import invalidate_after_interrupted_commit, is_cancellation, shield_from_cancellation
29
29
  from .connection import AsyncConnectionScope, apply_statement_timeout_sql
30
30
 
31
31
 
@@ -226,8 +226,10 @@ class _AsyncTransactionManager:
226
226
  except DatabaseCommitUnknownError:
227
227
  outcome = "commit_unknown"
228
228
  raise
229
- except BaseException:
230
- outcome = "rollback" # _commit() already attempted an internal rollback
229
+ except BaseException as commit_exc:
230
+ # Interrupted during COMMIT: the outcome is not known. Otherwise _commit() already
231
+ # attempted an internal rollback.
232
+ outcome = "rollback" if isinstance(commit_exc, Exception) else "commit_unknown"
231
233
  raise
232
234
  return False
233
235
  finally:
@@ -255,6 +257,13 @@ class _AsyncTransactionManager:
255
257
  try:
256
258
  await self._trans.commit()
257
259
  except BaseException as commit_exc:
260
+ if not isinstance(commit_exc, Exception):
261
+ # Interrupted (task cancellation, KeyboardInterrupt, SystemExit) during COMMIT:
262
+ # it may or may not have landed. A rollback would prove nothing; the connection's
263
+ # state is unknown, so it is invalidated (never reused), then the interruption
264
+ # propagates unchanged.
265
+ await invalidate_after_interrupted_commit(self._conn, commit_exc)
266
+ raise commit_exc
258
267
  # A failure during COMMIT may mean the transaction committed anyway (§15).
259
268
  if is_connection_error(commit_exc):
260
269
  raise DatabaseCommitUnknownError(
@@ -215,6 +215,13 @@ class TargetConfig:
215
215
  weight: int = 1
216
216
  pool: PoolConfig | None = None # falls back to defaults.pool
217
217
 
218
+ def __repr__(self) -> str:
219
+ # The URL may carry a password; reprs reach logs, tracebacks and reporters (§30).
220
+ return (
221
+ f"TargetConfig(url={redact_dsn(self.url)!r}, name={self.name!r}, "
222
+ f"required={self.required!r}, weight={self.weight!r}, pool={self.pool!r})"
223
+ )
224
+
218
225
  def resolved_pool(self, defaults: Defaults) -> PoolConfig:
219
226
  """This target's own pool config, or ``defaults.pool`` if it doesn't override one."""
220
227
  return self.pool or defaults.pool
@@ -0,0 +1,151 @@
1
+ """Secret redaction for messages, DSNs, and parameters (§13.4, §29).
2
+
3
+ Nothing that could carry credentials, tokens, or personal data may reach a log, trace,
4
+ metric, or error message unredacted. These helpers are intentionally conservative: when in
5
+ doubt, redact.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import re
11
+ from collections.abc import Mapping
12
+ from typing import Any
13
+ from urllib.parse import unquote, urlsplit, urlunsplit
14
+
15
+ REDACTED = "***"
16
+
17
+ # Redaction must stay linear on long, attacker-influenced error text (a server error can quote user
18
+ # input in full). The search-heavy parts (scheme, user name, key names, the DSN password search) are
19
+ # bounded and anchored; a value that follows a recognised key is consumed greedily to its natural
20
+ # end, with no closing delimiter required, so there is nothing to backtrack over and an over-long
21
+ # value is redacted whole (fail closed). Messages are cut to _MAX_MESSAGE before redaction.
22
+ #
23
+ # postgresql+psycopg://user:secret@host:5432/db -> redact the password component. As in
24
+ # SQLAlchemy's URL parser, the password runs from the ':' after the (possibly empty) user name to
25
+ # the next '@', so it may contain '/', '+', '=' or spaces; it stops at a line end. A password-less
26
+ # URL followed by an unrelated '@' later on the line ("postgresql://db:5432/app ... ops@corp") is
27
+ # recognised by its "port[/path]" then whitespace before any '@', and left readable.
28
+ _DSN_RE = re.compile(
29
+ r"(?P<pre>(?<![a-z0-9+.\-])[a-z][a-z0-9+.\-]{0,31}://[^:/@\s]{0,1024}:)"
30
+ r"(?!\d{1,5}(?:[/?][^@\s]{0,1024})?\s)(?P<pw>[^@\n]{0,4096}?)(?P<post>@)",
31
+ re.IGNORECASE,
32
+ )
33
+ # Only when a message was cut: a DSN whose '@' was cut off has its password run to the end (fail
34
+ # closed).
35
+ _CUT_DSN_RE = re.compile(
36
+ r"(?P<pre>(?<![a-z0-9+.\-])[a-z][a-z0-9+.\-]{0,31}://[^:/@\s]{0,1024}:)(?P<pw>[^@\n]*)\Z",
37
+ re.IGNORECASE,
38
+ )
39
+ # A URL query parameter whose (percent-decoded) key contains "password": SQLAlchemy splits the
40
+ # query on '&' only and decodes keys, so the value runs to '&' or whitespace ('#' is part of it).
41
+ # Only keys that can be such a key (containing "password" or a '%' escape) are consumed, so a
42
+ # nested "?next=/cb?password=..." is still seen.
43
+ _QUERY_RE = re.compile(
44
+ r"(?P<pre>[?&](?P<key>(?=[\w%.\-]{0,128}(?:password|%))[\w%.\-]{1,128})=)(?P<pw>[^&\s]*)",
45
+ re.IGNORECASE,
46
+ )
47
+ # Any other key containing "password", quoted or not, followed by '=' or ':' (PGPASSWORD=,
48
+ # db_password=, libpq keyword DSNs, "password": "x", password: x): a quoted value runs to its
49
+ # closing quote or the line end; an unquoted one to whitespace (',', '}', '&' and '#' are part of
50
+ # it; for a JSON number or literal this redacts a trailing ',' or '}' too, which is harmless).
51
+ _KEYWORD_RE = re.compile(
52
+ r"(?P<pre>(?<![\w?&%])[\"']?\w{0,64}password\w{0,64}[\"']?\s{0,8}[=:]\s{0,8})"
53
+ r"(?P<pw>\"(?:[^\"\\\n]|\\.)*\"?|'(?:[^'\\\n]|\\.)*'?|\S+)",
54
+ re.IGNORECASE,
55
+ )
56
+ _MAX_MESSAGE = 8192
57
+
58
+
59
+ def _query_value(match: re.Match[str]) -> str:
60
+ if "password" in unquote(match["key"]).lower():
61
+ return f"{match['pre']}{REDACTED}"
62
+ return match[0]
63
+
64
+
65
+ # Common secret-ish/PII key fragments; redacted from parameter maps unless caller opts out.
66
+ # This list is deliberately conservative and documented (not just here — see
67
+ # docs/troubleshooting.md's redaction section): it substring-matches credential and
68
+ # unambiguous-PII fragments, but cannot know an application's full schema. Anything outside
69
+ # this list — including context-dependent fields like email/phone that aren't always secret —
70
+ # must be declared via ``Query.sensitive_parameters``. See
71
+ # ``tests/property/test_invariants.py::test_hint_list_boundary_is_documented_and_tested`` for
72
+ # the exact, tested catch/miss boundary.
73
+ _SENSITIVE_KEY_HINTS = (
74
+ "password",
75
+ "passwd",
76
+ "secret",
77
+ "token",
78
+ "api_key",
79
+ "apikey",
80
+ "authorization",
81
+ "auth",
82
+ "credential",
83
+ "private_key",
84
+ "access_key",
85
+ "ssn",
86
+ "national_id",
87
+ "credit_card",
88
+ "card_number",
89
+ "cvv",
90
+ "iban",
91
+ "dob",
92
+ "date_of_birth",
93
+ "pin",
94
+ )
95
+
96
+
97
+ def redact_dsn(value: str) -> str:
98
+ """Redact the password in a URL/DSN while keeping it recognizable for debugging."""
99
+ redacted = _DSN_RE.sub(rf"\g<pre>{REDACTED}\g<post>", value)
100
+ redacted = _QUERY_RE.sub(_query_value, redacted)
101
+ redacted = _KEYWORD_RE.sub(rf"\g<pre>{REDACTED}", redacted)
102
+ # If urlsplit disagrees (e.g. odd formatting), fall back to a full rebuild.
103
+ try:
104
+ parts = urlsplit(redacted)
105
+ # Only for a URL value: in free text the "netloc" can run across words to an unrelated '@'.
106
+ if parts.password and not any(c.isspace() for c in parts.netloc):
107
+ netloc = parts.netloc.replace(f":{parts.password}@", f":{REDACTED}@")
108
+ redacted = urlunsplit(parts._replace(netloc=netloc))
109
+ except ValueError:
110
+ pass
111
+ return redacted
112
+
113
+
114
+ def is_sensitive_key(key: str) -> bool:
115
+ """Whether ``key``'s name suggests it holds a secret (password, token, etc.), by substring."""
116
+ lowered = key.lower()
117
+ return any(hint in lowered for hint in _SENSITIVE_KEY_HINTS)
118
+
119
+
120
+ def redact_params(
121
+ params: Mapping[str, Any] | None,
122
+ *,
123
+ sensitive: set[str] | None = None,
124
+ ) -> dict[str, Any]:
125
+ """Return a copy of ``params`` with sensitive values replaced by ``***``.
126
+
127
+ A key is redacted if it is named in ``sensitive`` (from ``Query.sensitive_parameters``)
128
+ or if it matches a built-in secret-ish hint.
129
+ """
130
+ if not params:
131
+ return {}
132
+ sensitive = sensitive or set()
133
+ out: dict[str, Any] = {}
134
+ for key, value in params.items():
135
+ if key in sensitive or is_sensitive_key(key):
136
+ out[key] = REDACTED
137
+ else:
138
+ out[key] = value
139
+ return out
140
+
141
+
142
+ def sanitize_message(message: str) -> str:
143
+ """Strip DSN passwords out of a free-form error/driver message. Long messages are cut to
144
+ ``_MAX_MESSAGE`` characters before redaction, so redaction time stays bounded (a server error
145
+ can quote a large user input) and no text from past the cut can reach the output."""
146
+ if len(message) <= _MAX_MESSAGE:
147
+ return redact_dsn(message)
148
+ # Cut first, so nothing past the cut can reach the output; a DSN password cut before its '@'
149
+ # is redacted to the end (keyword and query values already run to the end without a delimiter).
150
+ cut = _CUT_DSN_RE.sub(rf"\g<pre>{REDACTED}", message[:_MAX_MESSAGE])
151
+ return redact_dsn(cut) + " ...(truncated)"
@@ -80,3 +80,18 @@ def shield_from_cancellation(result: T) -> T:
80
80
  has already run to completion (mirrors ``_async/_compat.py``'s real ``asyncio.shield``-based
81
81
  version, which the async build genuinely needs)."""
82
82
  return result
83
+
84
+
85
+ def invalidate_after_interrupted_commit(conn: Any, original: BaseException) -> None:
86
+ """Drop a connection whose COMMIT was interrupted (outcome unknown) from the pool.
87
+
88
+ A failure while invalidating is noted on ``original`` (which the caller re-raises). A
89
+ KeyboardInterrupt or SystemExit raised while invalidating outranks the original interruption
90
+ and propagates, chained to it."""
91
+ try:
92
+ conn.invalidate()
93
+ except Exception as second:
94
+ original.add_note(
95
+ f"dbkit: {type(second).__name__} while invalidating the connection; "
96
+ "the invalidate did not finish"
97
+ )
@@ -21,6 +21,7 @@ from sqlalchemy import Engine, create_engine
21
21
 
22
22
  from .._core.config import DbkitConfig, PoolConfig, TargetConfig
23
23
  from .._core.errors import DatabaseConfigurationError, DatabaseRoutingError
24
+ from .._core.errors.redaction import sanitize_message
24
25
  from .._core.keys import EngineKey
25
26
  from .._core.routing import ResolvedRoute
26
27
  from .._pool import PoolInstrumentation, PoolSnapshot
@@ -139,9 +140,10 @@ class EngineRegistry:
139
140
  try:
140
141
  return create_engine(target.url, **kwargs)
141
142
  except Exception as exc:
142
- raise DatabaseConfigurationError(
143
- f"failed to create engine for {target.name!r}: {exc}"
144
- ) from exc
143
+ reason = sanitize_message(str(exc))
144
+ # Raised outside the except block, so the driver error (which can echo the URL, password
145
+ # included) is not even kept as __context__ (§30).
146
+ raise DatabaseConfigurationError(f"failed to create engine for {target.name!r}: {reason}")
145
147
 
146
148
  def get(self, route: ResolvedRoute) -> EngineEntry:
147
149
  """The cached engine for ``route``, creating (and, if needed, evicting) one lazily."""
@@ -37,7 +37,7 @@ from ..observability import logging as obslog
37
37
  from ..observability import metrics as m
38
38
  from ..observability.metrics import MetricsSink
39
39
  from ..observability.tracing import Tracer
40
- from ._compat import API_LABEL
40
+ from ._compat import API_LABEL, invalidate_after_interrupted_commit
41
41
  from .connection import ConnectionScope
42
42
  from .engine import EngineRegistry, EngineEntry
43
43
  from .resilience import ConcurrencyLimiter, run_with_retries
@@ -286,6 +286,13 @@ class ResilientExecutor:
286
286
  try:
287
287
  conn.commit()
288
288
  except BaseException as commit_exc:
289
+ if not isinstance(commit_exc, Exception):
290
+ # Interrupted during COMMIT (cancellation, KeyboardInterrupt,
291
+ # SystemExit): the outcome is unknown. No rollback; the connection is
292
+ # invalidated, never reused; the interruption propagates unchanged.
293
+ self._metrics.incr(m.COMMIT_UNKNOWN, labels=labels) # counted first
294
+ invalidate_after_interrupted_commit(conn, commit_exc)
295
+ raise commit_exc
289
296
  # Mirror _TransactionManager._commit(): a failure during COMMIT
290
297
  # may mean the write committed anyway (§15) — never silently swallow
291
298
  # that ambiguity, and never leave the exception unclassified either
@@ -28,7 +28,7 @@ from .._core.errors import (
28
28
  from ..observability import logging as obslog
29
29
  from ..observability import metrics as m
30
30
  from ..observability.metrics import MetricsSink, NoopMetrics
31
- from ._compat import is_cancellation, shield_from_cancellation
31
+ from ._compat import invalidate_after_interrupted_commit, is_cancellation, shield_from_cancellation
32
32
  from .connection import ConnectionScope, apply_statement_timeout_sql
33
33
 
34
34
 
@@ -229,8 +229,10 @@ class _TransactionManager:
229
229
  except DatabaseCommitUnknownError:
230
230
  outcome = "commit_unknown"
231
231
  raise
232
- except BaseException:
233
- outcome = "rollback" # _commit() already attempted an internal rollback
232
+ except BaseException as commit_exc:
233
+ # Interrupted during COMMIT: the outcome is not known. Otherwise _commit() already
234
+ # attempted an internal rollback.
235
+ outcome = "rollback" if isinstance(commit_exc, Exception) else "commit_unknown"
234
236
  raise
235
237
  return False
236
238
  finally:
@@ -258,6 +260,13 @@ class _TransactionManager:
258
260
  try:
259
261
  self._trans.commit()
260
262
  except BaseException as commit_exc:
263
+ if not isinstance(commit_exc, Exception):
264
+ # Interrupted (task cancellation, KeyboardInterrupt, SystemExit) during COMMIT:
265
+ # it may or may not have landed. A rollback would prove nothing; the connection's
266
+ # state is unknown, so it is invalidated (never reused), then the interruption
267
+ # propagates unchanged.
268
+ invalidate_after_interrupted_commit(self._conn, commit_exc)
269
+ raise commit_exc
261
270
  # A failure during COMMIT may mean the transaction committed anyway (§15).
262
271
  if is_connection_error(commit_exc):
263
272
  raise DatabaseCommitUnknownError(
@@ -0,0 +1,74 @@
1
+ """Cancellation during a real COMMIT, on PostgreSQL: it propagates unchanged and the connection,
2
+ whose transaction outcome is unknown, is invalidated (its backend goes away), not reused.
3
+
4
+ This checks the end-to-end result. SQLAlchemy also invalidates a connection on such exceptions,
5
+ so dbkit's own explicit invalidate is pinned by tests/unit/test_commit_cancellation.py."""
6
+
7
+ from __future__ import annotations
8
+
9
+ import asyncio
10
+ from collections.abc import AsyncIterator, Callable, Coroutine
11
+ from typing import Any
12
+
13
+ import pytest
14
+
15
+ from dbkit import AsyncDatabase, DatabaseTarget, sql
16
+
17
+ pytestmark = pytest.mark.integration
18
+
19
+ TARGET = DatabaseTarget(database="app", role="write")
20
+ SETUP = [
21
+ "CREATE TABLE IF NOT EXISTS dbkit_slow_commit (id integer PRIMARY KEY, pid integer NOT NULL)",
22
+ "TRUNCATE dbkit_slow_commit",
23
+ "CREATE OR REPLACE FUNCTION dbkit_sleep_at_commit() RETURNS trigger LANGUAGE plpgsql AS "
24
+ "$$BEGIN PERFORM pg_sleep(1); RETURN NULL; END$$",
25
+ "DROP TRIGGER IF EXISTS dbkit_sleep_at_commit ON dbkit_slow_commit",
26
+ "CREATE CONSTRAINT TRIGGER dbkit_sleep_at_commit AFTER INSERT ON dbkit_slow_commit "
27
+ "DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION dbkit_sleep_at_commit()",
28
+ ]
29
+ INSERT = sql("INSERT INTO dbkit_slow_commit (id, pid) VALUES (:id, pg_backend_pid()) RETURNING pid")
30
+ ALIVE = sql("SELECT count(*) AS n FROM pg_stat_activity WHERE pid = :pid")
31
+
32
+
33
+ @pytest.fixture
34
+ async def adb(base_config: dict) -> AsyncIterator[AsyncDatabase]:
35
+ db = AsyncDatabase.from_config(base_config)
36
+ await db.start()
37
+ for stmt in SETUP:
38
+ await db.execute(sql(stmt), target=TARGET)
39
+ try:
40
+ yield db
41
+ finally:
42
+ await db.execute(sql("DROP TABLE IF EXISTS dbkit_slow_commit"), target=TARGET)
43
+ await db.close()
44
+
45
+
46
+ async def _in_transaction(db: AsyncDatabase, pids: list[int]) -> None:
47
+ async with db.transaction(target=TARGET) as tx:
48
+ pids.append((await tx.fetch_one(INSERT, {"id": 1}))["pid"])
49
+
50
+
51
+ async def _auto_commit(db: AsyncDatabase, pids: list[int]) -> None:
52
+ async with db.connection(target=TARGET) as conn: # the auto-commit scope behind db.execute
53
+ pids.append((await conn.fetch_one(INSERT, {"id": 1}))["pid"])
54
+
55
+
56
+ @pytest.mark.parametrize("path", [_in_transaction, _auto_commit])
57
+ async def test_cancel_during_commit_propagates_and_discards_the_connection(
58
+ adb: AsyncDatabase, path: Callable[[AsyncDatabase, list[int]], Coroutine[Any, Any, None]]
59
+ ) -> None:
60
+ pids: list[int] = []
61
+ task = asyncio.create_task(path(adb, pids))
62
+ for _ in range(100): # until the statement ran and COMMIT is sleeping in the deferred trigger
63
+ if pids:
64
+ break
65
+ await asyncio.sleep(0.01)
66
+ await asyncio.sleep(0.2)
67
+ task.cancel()
68
+ with pytest.raises(asyncio.CancelledError):
69
+ await task
70
+ for _ in range(50): # the invalidated connection is closed, so its backend exits
71
+ if (await adb.fetch_one(ALIVE, {"pid": pids[0]}, target=TARGET))["n"] == 0:
72
+ break
73
+ await asyncio.sleep(0.1)
74
+ assert (await adb.fetch_one(ALIVE, {"pid": pids[0]}, target=TARGET))["n"] == 0