Skip to content

Fiddle: update database connection middleware to support streaming apis#133

Merged
krishan711 merged 3 commits into
mainfrom
dbconn
Apr 22, 2026
Merged

Fiddle: update database connection middleware to support streaming apis#133
krishan711 merged 3 commits into
mainfrom
dbconn

Conversation

@krishan711
Copy link
Copy Markdown
Contributor

Description

Screenshots:

Checklist:

  • I have updated the CHANGELOG with a summary of my changes

Copilot AI review requested due to automatic review settings April 22, 2026 14:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates middleware and request authorization typing to better support streaming endpoints, ensuring request-scoped resources remain available while the response body is being streamed.

Changes:

  • Reworked DatabaseConnectionMiddleware from BaseHTTPMiddleware to raw ASGI to keep the DB context open through streaming responses.
  • Updated authorize_bearer_jwt decorator typing to allow endpoints that return async iterators (streaming).
  • Removed the make type-check step from the Dockerfile build.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
core/api/middleware/database_connection_middleware.py Switches to raw ASGI middleware so DB context survives streaming response bodies.
core/api/authorizer.py Expands decorator typing/handling to support streaming handlers returning async iterators.
Dockerfile Removes type-check from image build (impacts where type-check enforcement occurs).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +21
return
async with self.database.create_context_connection():
response = await call_next(request)
return response
await self.app(scope, receive, send)
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create_context_connection() uses engine.begin() (a transaction) and this middleware now keeps that transaction open until the streaming response fully completes. For long-lived streams this can hold locks/retain MVCC snapshots and tie up a pooled connection for the entire client session. Consider using a non-transactional connection context for request-scoped connections (e.g., engine.connect()), or splitting streaming endpoints so DB work completes (and transaction closes) before yielding to the client.

Copilot uses AI. Check for mistakes.
Comment thread Dockerfile
@krishan711 krishan711 merged commit a2d1244 into main Apr 22, 2026
4 checks passed
@krishan711 krishan711 deleted the dbconn branch April 22, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants