Skip to content

Fix Python callback handle wrapping - #19870

Merged
Sébastien Ros (sebastienros) merged 1 commit into
mainfrom
sebros/fix-python-callback-wrappers
Sep 3, 2026
Merged

Fix Python callback handle wrapping#19870
Sébastien Ros (sebastienros) merged 1 commit into
mainfrom
sebros/fix-python-callback-wrappers

Conversation

@sebastienros

Copy link
Copy Markdown
Contributor

Description

Python callbacks exported as Action<IResourceBuilder<T>> received a raw Handle because .NET marshalled the callback argument with the generic builder ATS type ID while the generated Python wrapper registry used the concrete resource type ID. Calls such as with_host_port therefore failed at runtime.

Generated callback registrations now carry their concrete handle parameter type IDs. The Python runtime preserves exact runtime-type resolution and uses this metadata only as a fallback when the incoming type ID has no registered wrapper. This keeps other callback argument handling unchanged and does not alter TypeScript generation.

User-facing usage

Typed integration callbacks can invoke exported wrapper methods:

def configure_redis_commander(container: RedisCommanderResource) -> None:
    container.with_host_port(port=8082)

cache.with_redis_commander(configure_container=configure_redis_commander)

Regression coverage executes an exported Action<IResourceBuilder<TestRedisResource>> callback and verifies that the typed wrapper invokes another exported method. The Redis Python polyglot fixture also exercises RedisCommanderResource.with_host_port.

Validation:

  • Python code generation tests: 25 passed
  • TypeScript code generation tests: 128 passed
  • Redis Python AppHost restored and generated SDK callback execution invoked withRedisCommanderHostPort with port 8082

Fixes: #19869

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 2, 2026 18:29
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 19870

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 19870"

@github-actions github-actions Bot added the area-integrations Issues pertaining to Aspire Integrations packages label Sep 2, 2026
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Tests selector

2 / 99 PR test projects · 3 PR jobs · 0 advisory-only targets, from 7 changed files.

Selected PR test projects (2 / 99)

Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.RemoteHost.Tests

Selected PR jobs (3)

extension-e2e, polyglot, typescript-api-compat

Advisory workflow impact (0)

none


How these were chosen — grouped by what changed

🔧 src/Aspire.Hosting.CodeGeneration.Python/AtsPythonCodeGenerator.cs (changed source)
1 directly: Aspire.Hosting.CodeGeneration.Python.Tests
1 via the project graph: Aspire.Hosting.RemoteHost.Tests

🔧 src/Aspire.Hosting.CodeGeneration.Python/PythonModuleBuilder.cs (changed source)
1 directly: Aspire.Hosting.CodeGeneration.Python.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Python.Tests/AtsPythonCodeGeneratorTests.cs (changed test)
1 directly: Aspire.Hosting.CodeGeneration.Python.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Python.Tests/PythonTestExtensions.cs (changed test)
1 directly: Aspire.Hosting.CodeGeneration.Python.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/AtsGeneratedAspire.verified.py (changed test)
1 directly: Aspire.Hosting.CodeGeneration.Python.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py (changed test)
1 directly: Aspire.Hosting.CodeGeneration.Python.Tests

Job reasons

Job Triggered by
extension-e2e src/Aspire.Hosting.CodeGeneration.Python/AtsPythonCodeGenerator.cs, src/Aspire.Hosting.CodeGeneration.Python/PythonModuleBuilder.cs
• affected project Aspire.Hosting.CodeGeneration.Python
polyglot tests/PolyglotAppHosts/Aspire.Hosting.Redis/Python/apphost.py
• affected project Aspire.Hosting.CodeGeneration.Python
typescript-api-compat affected project Aspire.Hosting.CodeGeneration.Python

Selection computed for commit 051993c.

Copilot AI left a comment

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.

🟢 Approval recommended

The reviewed changes have regression coverage and no unresolved issues.

Pull request overview

Fixes Python callback handle wrapping so generic resource-builder callbacks resolve to typed generated wrappers.

Changes:

  • Adds callback parameter type IDs as fallback wrapper metadata.
  • Preserves exact runtime-type resolution.
  • Adds regression coverage and updates generated snapshots.
File summaries
File Description
tests/PolyglotAppHosts/Aspire.Hosting.Redis/Python/apphost.py Exercises the typed Redis Commander callback.
tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py Updates two-pass generation expectations.
tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/AtsGeneratedAspire.verified.py Updates generated Python expectations.
tests/Aspire.Hosting.CodeGeneration.Python.Tests/PythonTestExtensions.cs Adds the test callback export.
tests/Aspire.Hosting.CodeGeneration.Python.Tests/AtsPythonCodeGeneratorTests.cs Executes the callback regression scenario.
src/Aspire.Hosting.CodeGeneration.Python/PythonModuleBuilder.cs Applies fallback wrapper resolution.
src/Aspire.Hosting.CodeGeneration.Python/AtsPythonCodeGenerator.cs Emits callback handle type metadata.
Review details
  • Files reviewed: 6/7 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LGTM. The generated callback metadata fixes generic IResourceBuilder handle wrapping without changing exact-type resolution or TypeScript behavior, and the regression executes an exported method through the typed Python wrapper.

@sebastienros
Sébastien Ros (sebastienros) merged commit 197b509 into main Sep 3, 2026
88 checks passed
@sebastienros
Sébastien Ros (sebastienros) deleted the sebros/fix-python-callback-wrappers branch September 3, 2026 21:18
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 13.6 milestone Sep 3, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Pull request created: #1614

Generated by PR Documentation Check · auto · 118.1 AIC · ⌖ 17.6 AIC · ⊞ 19.6K

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

📝 Documentation has been drafted in microsoft/aspire.dev#1614 targeting release/13.6.

Added documentation for the Python callback handle wrapping fix:

  • whats-new/aspire-13-6.mdx: new bullet under Integration updates describing the fix and the configure_container/WithRedisCommander example.
  • extensibility/multi-language-integration-authoring.mdx: new note in the callback-context section explaining that Action<IResourceBuilder<T>> callbacks are marshalled by concrete resource type so guest-language wrappers (e.g. Python) resolve correctly.

Note

This draft PR needs human review before merging.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

⚠️ CI Failure Analysis: Possible Flaky Test(s)

The CI build failed due to test failure(s) that appear unrelated to the PR changes. These may be flaky tests.

Suspected flaky test(s):

Suggested actions:

  • Re-run the failed CI jobs to confirm if the failure is intermittent
  • If the test continues to fail, consider quarantining it using /quarantine-test <test name> <issue URL>
  • Search existing issues to see if this test is already known to be flaky

You can re-run the failed jobs from the workflow run page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-integrations Issues pertaining to Aspire Integrations packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python callbacks receive raw Handle for IResourceBuilder arguments

3 participants