Skip to content

feat(python): workflow context propagation quickstart#1309

Open
nelson-parente wants to merge 3 commits into
dapr:masterfrom
nelson-parente:feat/wf-ctx-propagation-python
Open

feat(python): workflow context propagation quickstart#1309
nelson-parente wants to merge 3 commits into
dapr:masterfrom
nelson-parente:feat/wf-ctx-propagation-python

Conversation

@nelson-parente
Copy link
Copy Markdown
Contributor

@nelson-parente nelson-parente commented May 19, 2026

Summary

  • Adds a new Python quickstart demonstrating workflow history propagation (Dapr 1.18 feature)
  • Ported from @cicoyle's canonical Go quickstart: dapr/quickstarts#1315 — same patient intake / e-prescribing scenario, same 3-level hierarchy, same workflow/activity names
  • Builds on Python SDK history propagation support landed in dapr/python-sdk#1025 and runtime support in dapr/dapr#9810

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.

PatientIntake (root)
  └─ VerifyInsurance       (activity, no propagation)
  └─ PrescribeMedication   (child wf, PropagationScope.LINEAGE)
        └─ CheckAllergies         (activity, no propagation)
        └─ ScreenDrugInteractions (activity, no propagation)
        └─ ComplianceAudit        (grandchild wf, PropagationScope.LINEAGE)
        |      reads PatientIntake + PrescribeMedication events
        └─ DispenseMedication     (activity, PropagationScope.OWN_HISTORY)
               reads PrescribeMedication events only

ComplianceAudit uses LINEAGE to verify the full ancestor chain. DispenseMedication uses OWN_HISTORY as a trust boundary — the pharmacy step doesn't get to see the upstream patient-intake chain.

Python API used (from dapr/python-sdk#1025)

  • PropagationScope.LINEAGE / PropagationScope.OWN_HISTORY
  • propagation= kwarg on ctx.call_child_workflow() and ctx.call_activity()
  • ctx.get_propagated_history()PropagatedHistory | None
  • PropagatedHistory.get_workflow_by_name(name)WorkflowResult
  • WorkflowResult.get_activity_by_name(name)ActivityResult (with .completed, .output)
  • PropagationNotFoundError

Replay safety

All print() calls inside workflows are guarded by if not ctx.is_replaying: so they only fire on the live execution, not on each durable replay.

Status — DRAFT

Pending before marking ready:

  • Smoke-test against Dapr 1.18 RC once dapr-ext-workflow==1.18.0rc0 is available
  • Confirm ctx.is_replaying is exposed as a property (not a method) in the Python SDK
  • Confirm dapr.yaml resourcesPath: ../../components resolves correctly
  • Add to CI matrix for Python quickstarts
  • Wait for sibling Go quickstart dapr/quickstarts#1315 to merge

Test plan

  • pip3 install -r requirements.txt with dapr-ext-workflow>=1.18.0rc0 available
  • dapr run -f . against Dapr 1.18 RC sidecar
  • ComplianceAudit reads correct ancestor history via LINEAGE (sees both PatientIntake + PrescribeMedication)
  • DispenseMedication sees only PrescribeMedication events via OWN_HISTORY
  • Older sidecar (pre-1.18) gracefully returns None from get_propagated_history() without crash

References

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>
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>
@nelson-parente nelson-parente marked this pull request as ready for review May 21, 2026 09:54
@nelson-parente nelson-parente requested review from a team as code owners May 21, 2026 09:54
@nelson-parente nelson-parente changed the title [DRAFT] feat(python): workflow context propagation quickstart feat(python): workflow context propagation quickstart May 21, 2026
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