Skip to content
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

Type changed for envelopeResult from getLroMetadata #311

Closed
tadelesh opened this issue Feb 26, 2024 · 4 comments
Closed

Type changed for envelopeResult from getLroMetadata #311

tadelesh opened this issue Feb 26, 2024 · 4 comments
Assignees
Labels
bug Something isn't working lib:azure-core Issues for @azure-tools/typespec-azure-core library

Comments

@tadelesh
Copy link
Member

tadelesh commented Feb 26, 2024

When calling getLroMetadata for createOrUpdate for the template resource, I got logicResult with right TypeSpec type Product, but envelopResult with a wrong calculated TypeSpec type ProxyResource as follow screenshot.
After some investigation, I found the type is changed after calling getEffectiveModelType here. Since the resource model has a path parameter, so it will enter the logic of finding a naming model which is same to the resource model without this path parameter (filter logic). When it has no exactly same model, it will also find a model that is same with it with the same filter logic, then the final result will fall to the original model. But after the complicated process, the type has totally changed and the naming info lost, it make the emitter hard to distinguish if it is the same resource model. Either fix the getEffectiveModelType logic for templated model or change the logic of getLroMetadata coudl resolve it. I don't know whether it should be opened as a core compiler problem or a getLroMetadata problem, If wrong place, I could move it.
image

@markcowl
Copy link
Member

markcowl commented Feb 26, 2024

@tadelesh I think this is by design, the finalEnvelopeResult (which matches the finalResult) is the value that should be used by emitters. The operations in the attached specs are a bit strange, as the interface template instantiates them without using TResource, which might be a factor in why the odd result, but the finalResult/finalEnvelopeResult/finalPath should be definitive, regardless.

@markcowl markcowl removed this from the [2024] April milestone Feb 26, 2024
@tadelesh
Copy link
Member Author

tadelesh commented Feb 27, 2024

Let me explain more clearly. The main problem here is for the following TypeSpec, when we call getEffectiveModelType, we will get the result type with same structure with Product, but another type with wrong name ProxyResource. I suppose it should return the type of Product.

model Product is ProxyResource<ProductProperties> {
  @doc("Name of product.")
  @pattern("^[\\w][\\w\\s]{1,48}[\\w]$|^\\.default$|^\\.unassigned$")
  @key("productName")
  @path
  @segment("products")
  name: string;
}

@tadelesh
Copy link
Member Author

tadelesh commented Mar 5, 2024

Let me explain more clearly. The main problem here is for the following TypeSpec, when we call getEffectiveModelType, we will get the result type with same structure with Product, but another type with wrong name ProxyResource. I suppose it should return the type of Product.

model Product is ProxyResource<ProductProperties> {
  @doc("Name of product.")
  @pattern("^[\\w][\\w\\s]{1,48}[\\w]$|^\\.default$|^\\.unassigned$")
  @key("productName")
  @path
  @segment("products")
  name: string;
}

@timotheeguerin do you think it is a bug for getEffectiveModelType?

@markcowl
Copy link
Member

This should be handled by the fix here: #1416

Closing as duplicate

ArcturusZhang added a commit to ArcturusZhang/typespec-azure that referenced this issue Nov 19, 2024
github-merge-queue bot pushed a commit that referenced this issue Dec 4, 2024
…RO (#1887)

Remove this workaround since #311 is closed.
Fixes #1752
Fixes #1530

This PR adds three new usage flags: `LroInitial`, `LroPolling`,
`LroFinalEnvelope`.
These new usage flags are previously represented by `Output`, now the
`Output` flag no longer contain the semantics of these usages.
Therefore, if a model's usage is only `LroInitial`, this means it is
only used as the initial response of an LRO.
if a model has both `LroInitial` and `Output`, this means it is used as
the initial response of an LRO, and it also used as a normal output in
other places.
The final result will not have above new usages unless it participates
as those roles as well. It will have output usage.
markcowl pushed a commit to markcowl/typespec-azure that referenced this issue Dec 5, 2024
…RO (Azure#1887)

Remove this workaround since Azure#311 is closed.
Fixes Azure#1752
Fixes Azure#1530

This PR adds three new usage flags: `LroInitial`, `LroPolling`,
`LroFinalEnvelope`.
These new usage flags are previously represented by `Output`, now the
`Output` flag no longer contain the semantics of these usages.
Therefore, if a model's usage is only `LroInitial`, this means it is
only used as the initial response of an LRO.
if a model has both `LroInitial` and `Output`, this means it is used as
the initial response of an LRO, and it also used as a normal output in
other places.
The final result will not have above new usages unless it participates
as those roles as well. It will have output usage.
iscai-msft pushed a commit that referenced this issue Dec 6, 2024
…RO (#1887)

Remove this workaround since #311 is closed.
Fixes #1752
Fixes #1530

This PR adds three new usage flags: `LroInitial`, `LroPolling`,
`LroFinalEnvelope`.
These new usage flags are previously represented by `Output`, now the
`Output` flag no longer contain the semantics of these usages.
Therefore, if a model's usage is only `LroInitial`, this means it is
only used as the initial response of an LRO.
if a model has both `LroInitial` and `Output`, this means it is used as
the initial response of an LRO, and it also used as a normal output in
other places.
The final result will not have above new usages unless it participates
as those roles as well. It will have output usage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lib:azure-core Issues for @azure-tools/typespec-azure-core library
Projects
None yet
Development

No branches or pull requests

4 participants