chore(examples): share one operation-status reader across the demos - #1319
Merged
Conversation
Six demos polled async operations through the same twelve-line dance,
branching on the response body's shape to pull out status and result.
The operations endpoints are free-form objects, so the generated model
carries only additional_properties and attribute access on it raises —
which is what the middle branch worked around, and why the getattr
fallback under it could never fire.
`operation_status` in _common/sdk.py reads the body through to_dict()
and hands back a plain dict, or {} when there was no body — a transient
blip mid-poll, which callers already treated as "ask again". Behaviour
is unchanged at every site, including for an error response or a body
without a status: the caller reads None and keeps polling, exactly as
before.
Three other additional_properties reads under examples/ are left alone
— memory_subgraph, upload_documents and roboledger_demo/validate read
different models, where this accessor does not apply.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Six demos polled async operations through the same twelve-line dance, branching on the response body's shape to extract
statusandresult:The operations endpoints are declared as free-form objects, so the generated model carries only
additional_propertiesand attribute access on it raises — that middle branch is the workaround, and thegetattrfallback beneath it was unreachable. This is the consumer-side echo of the client defect fixed in RoboFinSystems/robosystems-python-client#202: everyone hit the wall and hand-rolled the same escape.Changes
examples/_common/sdk.py—operation_status(client, operation_id)reads the body throughto_dict()and returns a plain dict, or{}when the response carried no body._scenario/runner.py,custom_graph_demo/create_graph.py,roboinvestor_demo/main.py,roboledger_demo/main.py,seattle_method_demo/main.py,seattle_method_world_online/main.py— each drops the dance for the helper and swaps the generated import for it. Net −99/+61 across seven files.Behaviour is unchanged at every site.
{}is falsy, so the existingcontinuestill fires on an empty body; an error response or a body without astatuskey yieldsstatus is None, so the loop keeps polling rather than mistaking it for a terminal state — same as before.Not touched
Three other
additional_propertiesreads underexamples/—custom_graph_demo/memory_subgraph.py,custom_graph_demo/upload_documents.py,roboledger_demo/validate.py— read different response models (period-close overflow, an investor payload). The operations accessor does not apply, so they stay as they are.This does not bump the client pin. The helper only needs
to_dict(), which has always been generated, so it works against the currently-locked 1.13.1. Moving to 1.13.2 (for the query/operator/operations retry parity in #202) is worth doing on its own merits and belongs in its own change.Testing
just test-code— ruff, format and basedpyright clean. Noteexamplesis in ruff'sexcludelist inpyproject.toml, so the tree is deliberately unlinted; these edits match the surrounding style by hand rather than by running a formatter over an excluded path.operation_statusexercised against a live stub for four cases: a completed operation (result.graph_idread back), a failed one, a 500 error body, and a 200 whose body omitsstatus— the last two yieldingstatus is Noneso a poll continues.