Skip to content

[Durable] Add Version property to $Context #1108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 6, 2025

Conversation

AnatoliB
Copy link
Contributor

Add Version property to the $Context object passed to orchestrator functions, matching the behavior implemented for .NET in-proc in Azure/azure-functions-durable-extension#3072.

As a result, PowerShell Functions users will be able to specify a version in host.json:

{
  "extensions": {
    "durableTask": {
      "defaultVersion": "2.0"
    }
  }
}

and check the orchestration version in their orchestrator functions in order to keep them backward compatible, for example:

if ($Context.Version -eq '1.0') {
    # Legacy code path
    Invoke-DurableActivity 'A'
} elseif ($Context.Version -eq '2.0') {
    # New code path
    Invoke-DurableActivity 'B'
}

Note: Microsoft.Azure.WebJobs.Extensions.DurableTask 3.1.0+ is required for this to work properly.

Pull request checklist

  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • I have added all required tests (Unit tests, E2E tests)

@AnatoliB
Copy link
Contributor Author

I want to add an E2E test for this, but this will require an extension bundle with Microsoft.Azure.WebJobs.Extensions.DurableTask 3.1.0+, so we'll have to do it later. For now, I tested E2E manually.

@AnatoliB AnatoliB requested review from andystaples and Copilot May 30, 2025 01:00
Copy link

@Copilot 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 a Version property to the orchestration context, enabling PowerShell Functions users to access version information for backward compatibility.

  • Introduces a lazy-loaded Version property in OrchestrationContext.
  • Implements version extraction logic in OrchestrationVersionExtractor and extends HistoryEvent to support the Version field.
  • Adds unit tests to validate the extracted version logic.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/Unit/Durable/OrchestrationVersionExtractorTests.cs Adds tests for various scenarios of version extraction.
src/DurableSDK/OrchestrationVersionExtractor.cs Implements logic to extract the version from orchestration history events.
src/DurableSDK/OrchestrationContext.cs Adds a lazy Version property that retrieves the version using the extractor.
src/DurableSDK/HistoryEvent.cs Extends the HistoryEvent model to include the Version property.
release_notes.md Updates release notes to document the new Version property.

AnatoliB added a commit to Azure/azure-functions-durable-powershell that referenced this pull request Jun 6, 2025
Add Version property to the `$Context` object passed to orchestrator
functions, similar to
Azure/azure-functions-powershell-worker#1108.

As a result, PowerShell Functions users will be able to specify a
version in **host.json**:

``` json
{
  "extensions": {
    "durableTask": {
      "defaultVersion": "2.0"
    }
  }
}
```

and check the orchestration version in their orchestrator functions in
order to keep them backward compatible, for example:

``` powershell
if ($Context.Version -eq '1.0') {
    # Legacy code path
    Invoke-DurableActivity 'A'
} elseif ($Context.Version -eq '2.0') {
    # New code path
    Invoke-DurableActivity 'B'
}
```

**Note: Microsoft.Azure.WebJobs.Extensions.DurableTask 3.1.0+ is
required for this to work properly.**

### Pull request checklist

* [x] My changes **do not** require documentation changes
  * [ ] Otherwise: Documentation issue linked to PR
* [ ] My changes **should not** be added to the release notes for the
next release
  * [x] Otherwise: I've added my notes to `release_notes.md`
* [x] My changes **do not** need to be backported to a previous version
  * [ ] Otherwise: Backport tracked by issue/PR #issue_or_pr
* [x] I have added all required tests (Unit tests, E2E tests)
@AnatoliB AnatoliB merged commit bd1bfa6 into dev Jun 6, 2025
7 checks passed
@AnatoliB AnatoliB deleted the anatolib/durable-context-version branch June 6, 2025 22:10
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.

2 participants