Repository navigation
[Python] Consume TCGC LRO status metadata and operation ID #12565
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
Draft
iscai-msft
wants to merge
11
commits into
microsoft:main
Choose a base branch
from
iscai-msft:python-tcgc-lro-metadata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,212
−53
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ccd6333
feat(python): expose selected LRO metadata and operation ID
b888e29
fix(python): load spec compiler options during regeneration
8ab24a9
Merge upstream main to unblock Python LRO CI
9a01aaf
fix(python): pass generated LRO metadata static checks
f53f293
test(python): xfail operation-id path case pending mock route fix
27aeee8
chore(python): drop redundant spec compiler option loading
1beb441
Revert "test(python): xfail operation-id path case pending mock route…
0cce65a
fix(python): address LRO metadata review
ab842e2
fix(python): exclude code-only fixture from README check
afacea3
test(python): reuse existing test infrastructure
c840df7
test(python): run polling regressions in CI-collected tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
.chronus/changes/python-lro-status-metadata-operation-id.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@typespec/http-client-python" | ||
| --- | ||
|
|
||
| Generate `MetadataLROPoller` and `AsyncMetadataLROPoller` for Azure operations using `@lroStatusMetadata` or `@lroOperationId`. Their `details` and `operation_id` properties expose selected monitor metadata and server-issued identifiers, refresh on polling, and repopulate after resuming from a continuation token. Operations without these annotations retain their existing pollers. | ||
|
|
||
| ```python | ||
| poller = client.begin_analyze(document) | ||
| result = poller.result() | ||
| print(poller.operation_id) | ||
| print(poller.details) | ||
| ``` |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -214,6 +214,7 @@ words: | |
| - onwarn | ||
| - openapi | ||
| - opfields | ||
| - operationid | ||
| - oxlint | ||
| - openapiv | ||
| - Packument | ||
|
|
||
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
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
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
126 changes: 126 additions & 0 deletions
126
packages/http-client-python/emitter/test/lro-metadata.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import { expectDiagnostics } from "@typespec/compiler/testing"; | ||
| import { expect, it } from "vitest"; | ||
| import { emitCodeModel } from "./test-host.js"; | ||
|
|
||
| it.each([true, false])( | ||
| "emits selected LRO paths without changing unannotated operations (%s)", | ||
| async (annotated) => { | ||
| const { codeModel, diagnostics } = await emitCodeModel(` | ||
| import "@azure-tools/typespec-azure-core"; | ||
| import "@azure-tools/typespec-client-generator-core"; | ||
| using TypeSpec.Http; | ||
| using Azure.Core; | ||
| using Azure.ClientGenerator.Core; | ||
|
|
||
| @service namespace Test; | ||
| model Usage { tokens: int32; } | ||
| model BaseStatus { | ||
| ${annotated ? "@lroStatusMetadata" : ""} | ||
| @clientName("progress") | ||
| @encodedName("application/json", "wire.progress") | ||
| usage?: Usage; | ||
| } | ||
| model Monitor extends BaseStatus { | ||
| ${annotated ? "@lroOperationId" : ""} | ||
| @encodedName("application/json", "server-id") | ||
| id: string; | ||
| status: Foundations.OperationState; | ||
| result?: string; | ||
| } | ||
| @get @route("/operations/{id}/status") | ||
| op poll(${annotated ? "@lroOperationId" : ""} @path id: string): Monitor; | ||
| @post @route("/jobs") | ||
| @pollingOperation(poll) | ||
| op start(): Foundations.AcceptedResponse<Monitor> & | ||
| Foundations.LongRunningStatusLocation<Monitor>; | ||
| `); | ||
| expectDiagnostics(diagnostics, []); | ||
| const client = codeModel.clients[0] as { | ||
| operationGroups: { operations: { name: string; lroMetadata?: unknown }[] }[]; | ||
| }; | ||
| const start = client.operationGroups | ||
| .flatMap((group) => group.operations) | ||
| .find((op) => op.name === "start"); | ||
| expect(start).toBeDefined(); | ||
| if (!annotated) { | ||
| expect(start).not.toHaveProperty("lroMetadata"); | ||
| return; | ||
| } | ||
| expect(start).toEqual( | ||
| expect.objectContaining({ | ||
| name: "start", | ||
| discriminator: "lro", | ||
| lroMetadata: expect.objectContaining({ | ||
| responseModel: expect.objectContaining({ name: "Monitor" }), | ||
| statusMetadata: [{ propertySegments: ["wire.progress"] }], | ||
| operationIdPath: ["server-id"], | ||
| operationIdUri: { | ||
| location: "ResponseHeader", | ||
| property: "Operation-Location", | ||
| pattern: "/operations/(?P<operation_id>[^/]+)/status/?$", | ||
| }, | ||
| initialResponseIsMonitor: true, | ||
| }), | ||
| }), | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| it.each(["{+id}", "{id*}"])( | ||
| "diagnoses unsupported operation-ID URI templates (%s)", | ||
| async (segment) => { | ||
| const { diagnostics } = await emitCodeModel(` | ||
| import "@azure-tools/typespec-azure-core"; | ||
| import "@azure-tools/typespec-client-generator-core"; | ||
| using TypeSpec.Http; | ||
| using Azure.Core; | ||
| using Azure.ClientGenerator.Core; | ||
|
|
||
| @service namespace Test; | ||
| model Monitor { status: Foundations.OperationState; result?: string; } | ||
| @get @route("/operations/${segment}/status") | ||
| op poll(@lroOperationId @path id: string): Monitor; | ||
| @post @route("/jobs") | ||
| @pollingOperation(poll) | ||
| op start(): Foundations.AcceptedResponse<Monitor> & | ||
| Foundations.LongRunningStatusLocation<Monitor>; | ||
| `); | ||
| expectDiagnostics(diagnostics, { | ||
| code: "@typespec/http-client-python/unsupported-lro-operation-id-template", | ||
| severity: "warning", | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| it("emits a path pattern for URI templates with other parameters and query expansions", async () => { | ||
| const { codeModel, diagnostics } = await emitCodeModel(` | ||
| import "@azure-tools/typespec-azure-core"; | ||
| import "@azure-tools/typespec-client-generator-core"; | ||
| using TypeSpec.Http; | ||
| using Azure.Core; | ||
| using Azure.ClientGenerator.Core; | ||
|
|
||
| @service namespace Test; | ||
| model Monitor { status: Foundations.OperationState; result?: string; } | ||
| @get @route("/v1.0/{account}/operations/{id}/status") | ||
| op poll(@path account: string, @lroOperationId @path id: string, @query apiVersion?: string): Monitor; | ||
| @post @route("/v1.0/{account}/jobs") | ||
| @pollingOperation(poll) | ||
| op start(@path account: string): Foundations.AcceptedResponse<Monitor> & | ||
| Foundations.LongRunningStatusLocation<Monitor>; | ||
| `); | ||
| expectDiagnostics(diagnostics, []); | ||
| const client = codeModel.clients[0] as { | ||
| operationGroups: { | ||
| operations: { name: string; lroMetadata?: { operationIdUri?: unknown } }[]; | ||
| }[]; | ||
| }; | ||
| const start = client.operationGroups | ||
| .flatMap((group) => group.operations) | ||
| .find((op) => op.name === "start"); | ||
| expect(start?.lroMetadata?.operationIdUri).toEqual({ | ||
| location: "ResponseHeader", | ||
| property: "Operation-Location", | ||
| pattern: "/v1\\.0/[^/]+/operations/(?P<operation_id>[^/]+)/status/?$", | ||
| }); | ||
| }); |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we having to access __raw here? is that something we could get from tcgc