-
Notifications
You must be signed in to change notification settings - Fork 218
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
Model assembler claims conflicting members - false positive #2004
Comments
Hey team, this is causing us more trouble nowadays. Can someone please triage the issue and drop some hints for a solution so that we can contribute a fix? |
The diff between the shape is due to the required trait from the mixin only being applied once since the trait gets “claimed” the first time the shape is built and removed from the unclaimed traits. When the shape gets built for the second time, the unclaimed traits is empty, so the member doesn’t get the required trait applied, and hence the comparison between previous and built shows a diff. There's a few ways we could go about this, but a simple way is to track what is "claimed" in addition to "unclaimed" (and don't remove items from unclaimed), and then if anything in unclaimed is not in claimed, validation event should be emitted (in |
Fixes smithy-lang#2004. When an apply statement targets a mixed in member, the trait application is stored until the mixed in member has been synthesized. However, if you load the same model file multiple times in the same loader, the trait application is only stored once, and removed when it is claimed, so when de-conflicting the duplicate mixed-in member definitions, only one of them will have the trait applied, resulting in a conflict. This commit updates the loader to keep track of when these unclaimed traits have been claimed, rather than just removing them when claimed. As long as the traits have been claimed once, we know they aren't being applied to a non-existent shape. This allows the traits to be claimed multiple times if necessary. Test cases were added for two different situations: 1. If the exact same model is loaded multiple times, so there are multiple instances where the traits need to be claimed. In this case there shouldn't be conflicts like in the issue. 2. If the apply statement is loaded multiple times, but the member it targets is only loaded once. In this case there shouldn't be any unclaimed traits, even though there are technically multiple of the same apply statements.
Fixes #2004. When an apply statement targets a mixed in member, the trait application is stored until the mixed in member has been synthesized. However, if you load the same model file multiple times in the same loader, the trait application is only stored once, and removed when it is claimed, so when de-conflicting the duplicate mixed-in member definitions, only one of them will have the trait applied, resulting in a conflict. This commit updates the loader to keep track of when these unclaimed traits have been claimed, rather than just removing them when claimed. As long as the traits have been claimed once, we know they aren't being applied to a non-existent shape. This allows the traits to be claimed multiple times if necessary. Test cases were added for two different situations: 1. If the exact same model is loaded multiple times, so there are multiple instances where the traits need to be claimed. In this case there shouldn't be conflicts like in the issue. 2. If the apply statement is loaded multiple times, but the member it targets is only loaded once. In this case there shouldn't be any unclaimed traits, even though there are technically multiple of the same apply statements.
Consider the following model IDL:
When you load and serialize this to Smithy again, you'll get an
apply
node for the@default
trait:This is also reflected in the normal
ModelSerializer
(outputting JSON):JSON dump
and it also loads fine if you have this one model file.
However, if you have another model file that happens to duplicate these structures, and you try to load them both during assembly, it fails:
That seems wrong: the model merging process is able to resolve the "conflict" once, but not twice, in what otherwise seemed like an idempotent process.
Is this something that should be fixed?
The entire process can be reproduced with the following scala-cli script:
The text was updated successfully, but these errors were encountered: