Fix crash in ClientProvider.BuildMethods when children list contains duplicates#10355
Fix crash in ClientProvider.BuildMethods when children list contains duplicates#10355
Conversation
… crash with duplicate children Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/b15af653-c208-49a5-bd0c-c7bef5ab6a6b Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/b15af653-c208-49a5-bd0c-c7bef5ab6a6b Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
|
|
||
| private IReadOnlyList<ClientProvider> GetSubClients() | ||
| { | ||
| var seen = new HashSet<ClientProvider>(); |
There was a problem hiding this comment.
@copilot instead of having this change in the generator, can we de-dup the children in the emitter so the generated code model has no duplicate entries?
There was a problem hiding this comment.
Moved the deduplication from the C# generator to the emitter in 4cd0636. The client-converter.ts now deduplicates children when populating the code model, and the ClientProvider.cs/ClientProviderTests.cs changes have been reverted.
…rator Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/01cbad23-efa3-4bc8-b1cb-9aa2ec7d8f59 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
| diagnostics.pipe(fromSdkClient(sdkContext, c, rootApiVersions)), | ||
| ); | ||
| const seen = new Set<InputClient>(); | ||
| inputClient.children = client.children |
There was a problem hiding this comment.
@copilot can we just create a loop and skip processing any client that was already visited? Can we also add TODO to remove this once Azure/typespec-azure#4251 is fixed?
There was a problem hiding this comment.
Done in 07b25f5. Replaced the .map().filter() chain with a loop that uses a Set<SdkClientType> to skip already-visited clients before converting them. Also added a TODO referencing Azure/typespec-azure#4251.
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/cd61d1eb-8886-47b1-8549-b54a5a329c54 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/fb528503-05e4-4f56-bbb0-51ea4188d6ae Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
jorgerangel-msft
left a comment
There was a problem hiding this comment.
@copilot rerun Generate.ps1 to ensure all generated test projects are regenerated. Ensure all tests pass as well, including spector tests
commit: |
Ran Generate.ps1 without a filter — no regenerated file changes were detected (all generated test projects were already up to date). All tests pass:
|
After TCGC 0.67.0 consolidated
SdkOperationGroupintoSdkClient,InputClient.Childrencan contain duplicate entries. This causesFields.ToDictionary(f => f.Name.ToVariableName())inBuildMethods()to throw "An item with the same key has already been added. Key: cachedGroup3" because duplicate sub-clients produce duplicate caching fields.Changes
client-converter.ts: Deduplicate children in the emitter when converting TCGC clients to the code model, using a loop with aSet<SdkClientType>to skip already-visited clients before converting them. Includes a TODO to remove the deduplication once Duplicate Client Children in Client Hierarchy Azure/typespec-azure#4251 is fixed.client-converter.test.ts: Add test with multiple nested@clientinterfaces that verifies no duplicate children appear in the generated code model when using@clientdecorators with operation groups