Fix Python callback handle wrapping - #19870
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 19870Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 19870" |
Tests selector2 / 99 PR test projects · 3 PR jobs · 0 advisory-only targets, from 7 changed files. Selected PR test projects (2 / 99)
Selected PR jobs (3)
Advisory workflow impact (0)none How these were chosen — grouped by what changed🔧 🔧 🧪 🧪 🧪 🧪 Job reasons
Selection computed for commit |
There was a problem hiding this comment.
🟢 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.
Sébastien Ros (sebastienros)
left a comment
There was a problem hiding this comment.
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.
|
Pull request created: #1614
|
|
📝 Documentation has been drafted in microsoft/aspire.dev#1614 targeting Added documentation for the Python callback handle wrapping fix:
Note This draft PR needs human review before merging. |
|
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:
You can re-run the failed jobs from the workflow run page. |
Description
Python callbacks exported as
Action<IResourceBuilder<T>>received a rawHandlebecause .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 aswith_host_porttherefore 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:
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 exercisesRedisCommanderResource.with_host_port.Validation:
withRedisCommanderHostPortwith port 8082Fixes: #19869
Checklist
<remarks />and<code />elements on your triple slash comments?