feat(python): workflow context propagation quickstart#1309
Open
nelson-parente wants to merge 4 commits into
Open
feat(python): workflow context propagation quickstart#1309nelson-parente wants to merge 4 commits into
nelson-parente wants to merge 4 commits into
Conversation
Ports Cassie Coyle's Go-SDK reference example (dapr/go-sdk#823) to Python. Demonstrates PropagationScope.LINEAGE and PropagationScope.OWN_HISTORY in a fraud-detection payment scenario with a 3-level workflow hierarchy. Requires Dapr 1.18+ (dapr/dapr#9810) and dapr-ext-workflow 1.18+ (dapr/python-sdk#1025). Signed-off-by: Nelson Parente <nelson_parente@live.com.pt>
7 tasks
Aligns the Python workflow history propagation quickstart with the canonical Go reference (dapr/go-sdk#823, dapr#1315) so all SDK quickstarts share the same patient intake / e-prescribing scenario. - Swap credit-card/fraud scenario for patient-intake/e-prescribing - Adopt PatientIntake -> PrescribeMedication -> ComplianceAudit hierarchy - Add is_replaying guards around all print() calls inside workflows - Use Cassie's PascalCase activity/workflow names for cross-SDK consistency Signed-off-by: Nelson Parente <nelson_parente@live.com.pt>
Aligns the Python workflow history propagation quickstart with Cassie's canonical Go version that merged into release-1.18 (dapr#1315, tutorials/workflow/go/history-propagation). Changes to match the canonical structure: - Move from workflows/python/sdk-context-propagation/order-processor/ to tutorials/workflow/python/history-propagation/, matching the Go sibling at tutorials/workflow/go/history-propagation/ - Split the monolithic app.py into app.py / workflow.py / models.py, mirroring main.go / workflow.go / models.go - Add ForwardLineage flag to PatientRecord and run both scenarios back-to-back (happy path + negative), purging state after each so the app exits on its own - Make DispenseMedication refuse to dispense when no propagated history is received, returning a refused DispenseResult with a Reason field - Match the Go README: title, propagation-scope table, STEP markers, expected output for both scenarios - dapr.yaml: appID=patient-app (was order-processor), resourcesPath=../../resources (was ../../components), appLogDestination/daprdLogDestination=console to match sister Python tutorials and Cassie's Go example - Use correct Python SDK API names: get_last_workflow_by_name / get_last_activity_by_name (the earlier draft used get_workflow_by_name / get_activity_by_name, which were renamed in dapr/python-sdk#1025) Signed-off-by: Nelson Parente <nelson_parente@live.com.pt>
Contributor
Author
|
Updated to align with @cicoyle's now-merged Go quickstart at Location & target branch
File layout
Behavioural alignment with the Go canonical version
Python SDK API
README
No SDK changes were required — the dependency stays at |
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
Python sibling of @cicoyle's canonical Go quickstart for workflow history propagation (Dapr 1.18). Same patient intake / e-prescribing scenario, same 3-level hierarchy, same workflow/activity names — so the Python and Go examples can be compared 1:1.
tutorials/workflow/go/history-propagation)dapr-ext-workflow==1.18.0rc0(dapr/python-sdk#1025)release-1.18to land alongside the Go example.Scenario
Patient intake / e-prescribing pipeline. A compliance audit and a pharmacy dispense step refuse to act unless the propagated history proves the required upstream checks (insurance, allergies, drug interactions) actually ran.
ComplianceAuditusesLINEAGEto verify the full ancestor chain.DispenseMedicationusesOWN_HISTORYas a trust boundary — the pharmacy step doesn't get to see the upstream patient-intake chain.Two scenarios (matches the Go demo)
The app schedules both back-to-back and exits on its own — no Ctrl+C needed:
PrescribeMedicationcallsDispenseMedicationwithPropagationScope.OWN_HISTORY; pharmacy verifies and dispenses.PrescribeMedicationcallsDispenseMedicationwithout propagation; pharmacy receives no history and refuses with arefusedDispenseResult.Python API used (from dapr/python-sdk#1025)
PropagationScope.LINEAGE/PropagationScope.OWN_HISTORYpropagation=kwarg onctx.call_child_workflow()andctx.call_activity()ctx.get_propagated_history()→PropagatedHistory | NonePropagatedHistory.get_last_workflow_by_name(name)→WorkflowResultWorkflowResult.get_last_activity_by_name(name)→ActivityResult(with.completed,.output)PropagationNotFoundErrorReplay safety
All
print()calls inside workflows are guarded byif not ctx.is_replaying:so they only fire on the live execution, not on each durable replay.Files
Test plan
pip3 install -r requirements.txtagainstdapr-ext-workflow==1.18.0rc0dapr run -f .against a Dapr 1.18 RC sidecarComplianceAuditreads full ancestor history viaLINEAGE(seesPatientIntake+PrescribeMedication);DispenseMedicationsees onlyPrescribeMedicationevents viaOWN_HISTORYand dispensesDispenseMedicationreceives no propagated history and returnsrefused,PrescribeMedicationreportspharmacy refused to dispenseNonefromget_propagated_history()without crashReferences
tutorials/workflow/go/history-propagation