Skip to content

fix:Add update_handler function for create_stream in python sdk#1406

Open
fanlia wants to merge 1 commit intoiii-hq:mainfrom
fanlia:patch-2
Open

fix:Add update_handler function for create_stream in python sdk#1406
fanlia wants to merge 1 commit intoiii-hq:mainfrom
fanlia:patch-2

Conversation

@fanlia
Copy link
Copy Markdown

@fanlia fanlia commented Apr 6, 2026

add missing update handler for create_stream

Summary by CodeRabbit

  • New Features
    • Stream update functionality is now available through the remote function interface, enabling modifications to streams alongside existing get, set, delete, and list operations.

add missing update handler for create_stream
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 6, 2026

@fanlia is attempting to deploy a commit to the motia Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 6, 2026

📝 Walkthrough

Walkthrough

Added StreamUpdateInput to imports and extended III.create_stream() to register a new stream::update remote function handler. The handler conditionally converts dict payloads to StreamUpdateInput objects and forwards them to the stream's update method, returning a typed list.

Changes

Cohort / File(s) Summary
Stream Update Handler Registration
sdk/packages/python/iii/src/iii/iii.py
Added StreamUpdateInput import and registered new stream::update({stream_name}) remote function with conditional dict-to-object conversion and forwarding logic to stream.update(...).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A stream now updates with grace so fine,
With StreamUpdateInput to align,
Dict becomes object, swift and true,
The remote function handles all anew! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly indicates the main change: adding an update_handler function to create_stream in the Python SDK.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
sdk/packages/python/iii/src/iii/iii.py (1)

1426-1429: Align update_handler return contract and normalization with set_handler and delete_handler.

update_handler is typed as list[Any] while stream.update() returns StreamUpdateResult | None, inconsistent with set_handler and delete_handler which both return Any and apply model_dump() normalization. This deviates from the established handler pattern and violates the consistency requirement across stream operations.

Suggested adjustment
-        async def update_handler(data: Any) -> list[Any]:
+        async def update_handler(data: Any) -> Any:
             input_data = StreamUpdateInput(**data) if isinstance(data, dict) else data
-            return await stream.update(input_data)
+            result = await stream.update(input_data)
+            return result.model_dump() if result else None
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/packages/python/iii/src/iii/iii.py` around lines 1426 - 1429, The
update_handler currently declares return type list[Any] and directly returns
stream.update(input_data), but stream.update returns StreamUpdateResult | None
and handlers should follow the same pattern as set_handler/delete_handler by
returning Any and normalizing responses via model_dump(); change update_handler
to return Any, call StreamUpdateInput for dicts as now, await
stream.update(input_data), then if result is not None apply result.model_dump()
(or equivalent normalization used by set_handler/delete_handler) and return
that, otherwise return None to preserve the contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@sdk/packages/python/iii/src/iii/iii.py`:
- Line 1437: The create_stream() docstring is incorrect about update not being
registered; update the docstring for create_stream() to reflect that
register_function is called with {"id": f"stream::update({stream_name})"} and
thus an update handler (update_handler) is registered for the stream;
specifically mention that stream::update(<stream_name>) is registered via
register_function and describe the behavior of update_handler (what it
expects/does) so docs align with the implemented registration.

---

Nitpick comments:
In `@sdk/packages/python/iii/src/iii/iii.py`:
- Around line 1426-1429: The update_handler currently declares return type
list[Any] and directly returns stream.update(input_data), but stream.update
returns StreamUpdateResult | None and handlers should follow the same pattern as
set_handler/delete_handler by returning Any and normalizing responses via
model_dump(); change update_handler to return Any, call StreamUpdateInput for
dicts as now, await stream.update(input_data), then if result is not None apply
result.model_dump() (or equivalent normalization used by
set_handler/delete_handler) and return that, otherwise return None to preserve
the contract.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f7dade86-38ad-4b14-ba81-840b53ba8fc7

📥 Commits

Reviewing files that changed from the base of the PR and between 7677350 and c985fda.

📒 Files selected for processing (1)
  • sdk/packages/python/iii/src/iii/iii.py

self.register_function(
{"id": f"stream::list_groups({stream_name})"}, list_groups_handler
)
self.register_function({"id": f"stream::update({stream_name})"}, update_handler)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Update create_stream() docstring to match the new behavior.

After registering stream::update(...), the docstring still states that update is not registered. Please update the method docs so SDK behavior and documentation stay aligned.

As per coding guidelines, "Check for related inconsistencies with the docs/".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/packages/python/iii/src/iii/iii.py` at line 1437, The create_stream()
docstring is incorrect about update not being registered; update the docstring
for create_stream() to reflect that register_function is called with {"id":
f"stream::update({stream_name})"} and thus an update handler (update_handler) is
registered for the stream; specifically mention that
stream::update(<stream_name>) is registered via register_function and describe
the behavior of update_handler (what it expects/does) so docs align with the
implemented registration.

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.

1 participant