kiba-core 0.5.3.dev94__tar.gz → 0.5.3.dev96__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 (146) hide show
  1. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/CHANGELOG.md +2 -0
  2. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/PKG-INFO +1 -1
  3. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/middleware/database_connection_middleware.py +6 -2
  4. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/middleware/exception_handling_middleware.py +3 -0
  5. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/kiba_core.egg-info/PKG-INFO +1 -1
  6. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/pyproject.toml +1 -1
  7. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/api/test_database_connection_middleware.py +22 -0
  8. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/api/test_exception_handling_middleware.py +21 -0
  9. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/.github/pull_request_template.md +0 -0
  10. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/.github/workflows/deploy.yml +0 -0
  11. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/.github/workflows/publish.yml +0 -0
  12. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/.github/workflows/pull-request.yml +0 -0
  13. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/.github/workflows/release.yml +0 -0
  14. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/.gitignore +0 -0
  15. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/Dockerfile +0 -0
  16. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/README.md +0 -0
  17. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/__init__.py +0 -0
  18. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/__init__.py +0 -0
  19. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/api_request.py +0 -0
  20. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/api_response.py +0 -0
  21. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/authorizer.py +0 -0
  22. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/default_routes.py +0 -0
  23. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/health.py +0 -0
  24. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/json_route.py +0 -0
  25. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/middleware/__init__.py +0 -0
  26. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/middleware/logging_middleware.py +0 -0
  27. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/middleware/origin_ip_middleware.py +0 -0
  28. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/middleware/server_headers_middleware.py +0 -0
  29. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/openapi.py +0 -0
  30. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/rate_limit.py +0 -0
  31. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/request_body.py +0 -0
  32. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/request_context.py +0 -0
  33. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/route.py +0 -0
  34. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/route_auth.py +0 -0
  35. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/route_metadata.py +0 -0
  36. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/streaming_json_route.py +0 -0
  37. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/api/uploaded_file.py +0 -0
  38. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/aws_requester.py +0 -0
  39. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/caching/__init__.py +0 -0
  40. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/caching/cache.py +0 -0
  41. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/caching/dict_cache.py +0 -0
  42. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/caching/file_cache.py +0 -0
  43. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/cron/__init__.py +0 -0
  44. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/cron/api_request_cron_job_processor.py +0 -0
  45. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/cron/cron_executor.py +0 -0
  46. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/cron/cron_job_processor.py +0 -0
  47. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/cron/model.py +0 -0
  48. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/exceptions.py +0 -0
  49. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/http/__init__.py +0 -0
  50. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/http/basic_authentication.py +0 -0
  51. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/http/jwt.py +0 -0
  52. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/http/rest_method.py +0 -0
  53. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/locks/__init__.py +0 -0
  54. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/locks/lock.py +0 -0
  55. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/locks/model.py +0 -0
  56. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/locks/sql.py +0 -0
  57. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/logging.py +0 -0
  58. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/notifications/__init__.py +0 -0
  59. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/notifications/discord_client.py +0 -0
  60. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/notifications/notification_client.py +0 -0
  61. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/notifications/slack_client.py +0 -0
  62. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/py.typed +0 -0
  63. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/queues/__init__.py +0 -0
  64. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/queues/aqs.py +0 -0
  65. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/queues/cosmos.py +0 -0
  66. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/queues/message_queue.py +0 -0
  67. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/queues/message_queue_processor.py +0 -0
  68. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/queues/model.py +0 -0
  69. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/queues/sql.py +0 -0
  70. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/queues/sqs.py +0 -0
  71. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/requester/__init__.py +0 -0
  72. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/requester/requester.py +0 -0
  73. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/s3_manager.py +0 -0
  74. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/service_client.py +0 -0
  75. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/store/__init__.py +0 -0
  76. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/store/database.py +0 -0
  77. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/store/entity_repository.py +0 -0
  78. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/store/retriever.py +0 -0
  79. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/store/saver.py +0 -0
  80. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/util/__init__.py +0 -0
  81. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/util/async_util.py +0 -0
  82. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/util/chain_util.py +0 -0
  83. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/util/date_util.py +0 -0
  84. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/util/dict_util.py +0 -0
  85. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/util/file_util.py +0 -0
  86. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/util/hashing_util.py +0 -0
  87. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/util/http_util.py +0 -0
  88. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/util/json_util.py +0 -0
  89. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/util/list_util.py +0 -0
  90. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/util/process_util.py +0 -0
  91. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/util/string_util.py +0 -0
  92. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/util/typing_util.py +0 -0
  93. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/util/url_util.py +0 -0
  94. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/util/value_holder.py +0 -0
  95. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/web3/__init__.py +0 -0
  96. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/web3/eth_client.py +0 -0
  97. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/web3/eth_client_registry.py +0 -0
  98. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/core/web3/multicall3.py +0 -0
  99. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/kiba_core.egg-info/SOURCES.txt +0 -0
  100. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/kiba_core.egg-info/dependency_links.txt +0 -0
  101. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/kiba_core.egg-info/requires.txt +0 -0
  102. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/kiba_core.egg-info/top_level.txt +0 -0
  103. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/makefile +0 -0
  104. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/setup.cfg +0 -0
  105. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/__init__.py +0 -0
  106. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/api/test_api_response.py +0 -0
  107. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/api/test_authorizer.py +0 -0
  108. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/api/test_json_route.py +0 -0
  109. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/api/test_openapi.py +0 -0
  110. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/api/test_origin_ip_middleware.py +0 -0
  111. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/api/test_rate_limit.py +0 -0
  112. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/api/test_request_context.py +0 -0
  113. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/api/test_route.py +0 -0
  114. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/api/test_streaming_json_route.py +0 -0
  115. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/caching/test_dict_cache.py +0 -0
  116. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/caching/test_file_cache.py +0 -0
  117. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/cron/__init__.py +0 -0
  118. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/cron/test_cron_executor.py +0 -0
  119. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/locks/test_sql_lock.py +0 -0
  120. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/queues/conftest.py +0 -0
  121. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/queues/test_aqs_queue.py +0 -0
  122. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/queues/test_cosmos_queue.py +0 -0
  123. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/queues/test_message_queue_processor.py +0 -0
  124. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/queues/test_sql_queue.py +0 -0
  125. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/queues/test_sqs_queue.py +0 -0
  126. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/requester/__init__.py +0 -0
  127. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/requester/test_requester.py +0 -0
  128. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/test_database.py +0 -0
  129. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/test_entity_repository.py +0 -0
  130. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/test_exceptions.py +0 -0
  131. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/test_logging.py +0 -0
  132. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/util/__init__.py +0 -0
  133. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/util/test_async_util.py +0 -0
  134. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/util/test_chain_util.py +0 -0
  135. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/util/test_date_util.py +0 -0
  136. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/util/test_dict_util.py +0 -0
  137. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/util/test_file_util.py +0 -0
  138. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/util/test_json_util.py +0 -0
  139. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/util/test_list_util.py +0 -0
  140. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/util/test_process_util.py +0 -0
  141. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/util/test_string_util.py +0 -0
  142. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/util/test_url_util.py +0 -0
  143. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/web3/__init__.py +0 -0
  144. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/web3/test_eth_client_registry.py +0 -0
  145. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/tests/web3/test_rest_eth_client.py +0 -0
  146. {kiba_core-0.5.3.dev94 → kiba_core-0.5.3.dev96}/uv.lock +0 -0
@@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
8
8
  ## [Unreleased]
9
9
 
10
10
  ### Added
11
+ - [MINOR] Added `excludedPaths` (exact) and `excludedPathPrefixes` to `DatabaseConnectionMiddleware`: matching requests run without a context connection, e.g. a long-lived SSE stream that shouldn't hold a pooled connection and open transaction, or routes that use a different database
12
+ - [PATCH] Updated `ExceptionHandlingMiddleware` to answer a client that disconnects before the response starts (starlette's `ClientDisconnect`, e.g. while reading the body) with a 499 instead of logging a traceback and a 500
11
13
  - [MAJOR] Added `priority` to `SqlMessageQueue.send_message` and `send_messages` (default 0): visible messages are claimed highest priority first, then by `visibleDate`, and a duplicate send, or a retry folded into a pending duplicate, keeps the higher priority. `tbl_queue_messages` has a new `priority` column (`INTEGER NOT NULL DEFAULT 0`), so apps must add it with a migration before upgrading
12
14
  - [PATCH] Fixed `DatabaseConnectionMiddleware`'s commit when the response starts failing ("another operation is in progress") for streaming responses behind a `BaseHTTPMiddleware`: `Database.execute` and `Database.commit_context_connection` now wait for each other on the same connection
13
15
  - [MINOR] Added `Database.commit_context_connection` to commit the context connection's writes so far; anything run on it afterwards is committed when the context connection ends
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kiba-core
3
- Version: 0.5.3.dev94
3
+ Version: 0.5.3.dev96
4
4
  Summary: Kiba Labs' python utilities
5
5
  Project-URL: repository, https://github.com/kibalabs/core-py
6
6
  Requires-Python: <4,>=3.12
@@ -1,3 +1,5 @@
1
+ from collections.abc import Collection
2
+
1
3
  from starlette.types import ASGIApp
2
4
  from starlette.types import Message
3
5
  from starlette.types import Receive
@@ -8,14 +10,16 @@ from core.store.database import Database
8
10
 
9
11
 
10
12
  class DatabaseConnectionMiddleware:
11
- def __init__(self, app: ASGIApp, database: Database) -> None:
13
+ def __init__(self, app: ASGIApp, database: Database, excludedPaths: Collection[str] = (), excludedPathPrefixes: Collection[str] = ()) -> None:
12
14
  self.app = app
13
15
  self.database = database
16
+ self.excludedPaths = frozenset(excludedPaths)
17
+ self.excludedPathPrefixes = tuple(excludedPathPrefixes)
14
18
 
15
19
  # NOTE(krishan711): see note in database.py about why this can cause problems with concurrent operations
16
20
  # NOTE(krishan711): raw ASGI (not BaseHTTPMiddleware) so the DB connection stays open across streaming body
17
21
  async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
18
- if scope['type'] != 'http':
22
+ if scope['type'] != 'http' or scope['path'] in self.excludedPaths or scope['path'].startswith(self.excludedPathPrefixes):
19
23
  await self.app(scope, receive, send)
20
24
  return
21
25
  async with self.database.create_context_connection():
@@ -1,5 +1,6 @@
1
1
  from starlette.middleware.base import BaseHTTPMiddleware
2
2
  from starlette.middleware.base import RequestResponseEndpoint
3
+ from starlette.requests import ClientDisconnect
3
4
  from starlette.requests import Request
4
5
  from starlette.responses import Response
5
6
  from starlette.types import ASGIApp
@@ -29,6 +30,8 @@ class ExceptionHandlingMiddleware(BaseHTTPMiddleware):
29
30
  except RedirectException as exception:
30
31
  response = Response(status_code=exception.statusCode)
31
32
  response.headers.update(exception.outgoing_headers())
33
+ except ClientDisconnect:
34
+ response = Response(status_code=499)
32
35
  except ClientException as exception:
33
36
  if self.shouldSquashClientExceptions:
34
37
  logging.error(f'{exception.exceptionType} occurred: {exception.message}')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kiba-core
3
- Version: 0.5.3.dev94
3
+ Version: 0.5.3.dev96
4
4
  Summary: Kiba Labs' python utilities
5
5
  Project-URL: repository, https://github.com/kibalabs/core-py
6
6
  Requires-Python: <4,>=3.12
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "kiba-core"
3
- version = "0.5.3.dev94"
3
+ version = "0.5.3.dev96"
4
4
  description = "Kiba Labs' python utilities"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12, <4"
@@ -99,6 +99,28 @@ async def test_writes_are_rolled_back_when_the_request_fails_before_responding(d
99
99
  assert await get_record_names(database=database) == []
100
100
 
101
101
 
102
+ @pytest.mark.asyncio
103
+ @pytest.mark.parametrize(('path', 'isExcluded'), [('/live-events', True), ('/live-events/123', False), ('/mcp', True), ('/mcp/exports/token', True), ('/v1/mcp', False), ('/', False)])
104
+ async def test_excluded_paths_run_without_a_context_connection(database, path, isExcluded):
105
+ hasContextConnectionHolder: list[bool] = []
106
+
107
+ async def app(scope, receive, send):
108
+ hasContextConnectionHolder.append(database._get_context_connection() is not None)
109
+ await send({'type': 'http.response.start', 'status': 200, 'headers': []})
110
+ await send({'type': 'http.response.body', 'body': b'ok'})
111
+
112
+ async def receive():
113
+ return {'type': 'http.request', 'body': b'', 'more_body': False}
114
+
115
+ async def send(message):
116
+ pass
117
+
118
+ middleware = DatabaseConnectionMiddleware(app=app, database=database, excludedPaths={'/live-events'}, excludedPathPrefixes=('/mcp',))
119
+ await middleware({'type': 'http', 'method': 'GET', 'path': path}, receive, send)
120
+
121
+ assert hasContextConnectionHolder == [not isExcluded]
122
+
123
+
102
124
  async def post_to_app(app) -> tuple[int, bytes]:
103
125
  scope = {
104
126
  'type': 'http', 'asgi': {'version': '3.0'}, 'http_version': '1.1', 'method': 'POST', 'scheme': 'http', 'path': '/', 'raw_path': b'/',
@@ -119,3 +119,24 @@ def test_plain_exception_has_no_extra_headers(plain_error_client):
119
119
  assert response.status_code == 400
120
120
  assert 'retry-after' not in response.headers
121
121
  assert 'location' not in response.headers
122
+
123
+
124
+ @pytest.mark.asyncio
125
+ async def test_client_disconnect_while_reading_body_returns_499():
126
+ @json_route(requestType=SimpleRequest, responseType=SimpleResponse)
127
+ async def endpoint(request: KibaApiRequest[SimpleRequest]) -> SimpleResponse:
128
+ return SimpleResponse(result=request.data.value)
129
+
130
+ app = Starlette(routes=[Route('/echo', endpoint, methods=['POST'])])
131
+ app.add_middleware(ExceptionHandlingMiddleware)
132
+ sentMessages = []
133
+
134
+ async def receive():
135
+ return {'type': 'http.disconnect'}
136
+
137
+ async def send(message):
138
+ sentMessages.append(message)
139
+
140
+ scope = {'type': 'http', 'asgi': {'version': '3.0'}, 'method': 'POST', 'path': '/echo', 'headers': [(b'content-type', b'application/json')], 'query_string': b''}
141
+ await app(scope, receive, send)
142
+ assert sentMessages[0]['status'] == 499
File without changes