8000 Add context manager support by igalshilman · Pull Request #149 · restatedev/sdk-python · GitHub
[go: up one dir, main page]

Skip to content

Add context manager support#149

Merged
igalshilman merged 3 commits intomainfrom
add_context_manager
Nov 21, 2025
Merged

Add context manager support#149
igalshilman merged 3 commits intomainfrom
add_context_manager

Conversation

@igalshilman
Copy link
Contributor

No description provided.

@github-actions
Copy link
github-actions bot commented Nov 21, 2025

Test Results

  7 files  ±0    7 suites  ±0   4m 27s ⏱️ -11s
 49 tests ±0   49 ✅ ±0  0 💤 ±0  0 ❌ ±0 
210 runs  ±0  210 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 667d001. ± Comparison against base commit eb8e2fd.

♻️ This comment has been updated with latest results.

@igalshilman igalshilman requested a review from Copilot November 21, 2025 14:00
Copy link
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

This PR adds context manager support to the Restate SDK, allowing handlers to specify async context managers that will be automatically entered/exited during handler invocation. The feature includes a contextvar utility decorator that captures yielded values in context variables for easy access within handlers.

Key changes:

  • Added contextvar decorator for async context managers that stores yielded values in context variables
  • Extended Service, Object, and Workflow classes to accept and combine context managers at both class and handler level
  • Integrated context manager execution into the handler invocation flow using AsyncExitStack

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
python/restate/context_managers.py New file implementing the contextvar decorator utility
python/restate/extensions.py Exports the new contextvar decorator
python/restate/handler.py Added context_managers field to Handler dataclass and make_handler function
python/restate/service.py Added context_managers parameter to Service class and handler decorator with combining logic
python/restate/object.py Added context_managers parameter to VirtualObject class and handler decorator with combining logic
python/restate/workflow.py Added context_managers parameter to Workflow class, main, and handler decorators with combining logic
python/restate/server_context.py Integrated AsyncExitStack to enter context managers during handler invocation
tests/ext.py Added test demonstrating context manager usage with the contextvar decorator

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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@igalshilman igalshilman merged commit cd1e8e3 into main Nov 21, 2025
6 checks passed
@igalshilman igalshilman deleted the add_context_manager branch November 21, 2025 17:01
@github-actions github-actions bot locked and limited conversation to collaborators Nov 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0