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

Fix 3 bugs in @length-constrained collection and map shapes #2085

Conversation

david-perez
Copy link
Contributor

The 3 bugs are related, hence why a single commit to address them all.

  1. Implement @length on collections #2028 added support for the @length constraint trait on collection
    shapes, but the code enforcing the trait was not being exercised upon
    receiving a request, specifically when converting the input
    unconstrained list into the constrained one. Note that Implement @length on collections #2028 did not
    result in the removal of the relevant protocol tests from
    ServerProtocolTestGenerator's list of known failing tests.
  2. Fixes code generation of @length-constrained list shapes whose
    members are not constrained: the converter being generated only
    worked for the case where the member was (transitively) constrained.
    The constraints.smithy model has been expanded to cover this case.
  3. Fixes bug in code generation, when the
    codegenConfig.publicConstrainedTypes setting is set to false, of
    @length-constrained map shapes and collection shapes whose values
    or members (respectively) are constrained, but result in Rust types
    that would have been public regardless of the setting's value. This
    is the case only when they are modeled as structure shapes or union
    shapes. In these cases, two converters from the constrained type to
    the inner type were being generated, resulting in two From trait
    implementations. The constraints.smithy model has been expanded to
    cover this case.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

The 3 bugs are related, hence why a single commit to address them all.

1. #2028 added support for the `@length` constraint trait on collection
   shapes, but the code enforcing the trait was not being exercised upon
   receiving a request, specifically when converting the input
   unconstrained list into the constrained one. Note that #2028 did not
   result in the removal of the relevant protocol tests from
   `ServerProtocolTestGenerator`'s list of known failing tests.
2. Fixes code generation of `@length`-constrained list shapes whose
   members are not constrained: the converter being generated only
   worked for the case where the member was (transitively) constrained.
   The `constraints.smithy` model has been expanded to cover this case.
3. Fixes bug in code generation, when the
   `codegenConfig.publicConstrainedTypes` setting is set to `false`, of
   `@length`-constrained map shapes and collection shapes whose values
   or members (respectively) are constrained, but result in Rust types
   that would have been public regardless of the setting's value. This
   is the case only when they are modeled as structure shapes or union
   shapes. In these cases, two converters from the constrained type to
   the inner type were being generated, resulting in two `From` trait
   implementations. The `constraints.smithy` model has been expanded to
   cover this case.
@david-perez david-perez added the server Rust server SDK label Dec 9, 2022
@david-perez david-perez requested review from a team as code owners December 9, 2022 16:57
LukeMathWalker
LukeMathWalker previously approved these changes Dec 9, 2022
@github-actions
Copy link

github-actions bot commented Dec 9, 2022

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

github-actions bot commented Dec 9, 2022

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@LukeMathWalker LukeMathWalker enabled auto-merge (squash) December 12, 2022 11:05
@LukeMathWalker LukeMathWalker merged commit e1ba656 into main Dec 12, 2022
@LukeMathWalker LukeMathWalker deleted the davidpz/fix-3-bugs-in-length-constrained-collection-and-map-shapes branch December 12, 2022 11:09
david-perez added a commit that referenced this pull request Dec 14, 2022
…strained

The generated code these should have emitted was fixed in #2085 (it's
bug number 2), but code generation is still crashing because the call to
calculate the inner constraint violation symbol is performed _before_
checking that the collection's member can reach a constrained shape.

The test that #2085 added in `constraints.smithy`:

```smithy
@Length(max: 69)
list LengthList {
    member: ConB
}
```

was not exercising what it should have, since `ConB`, is its name hints
at, is a constrained structure shape.
jjant added a commit that referenced this pull request Dec 15, 2022
…strained (#2103)

* Fix `@length`-constrained collection shapes whose members are not constrained

The generated code these should have emitted was fixed in #2085 (it's
bug number 2), but code generation is still crashing because the call to
calculate the inner constraint violation symbol is performed _before_
checking that the collection's member can reach a constrained shape.

The test that #2085 added in `constraints.smithy`:

```smithy
@Length(max: 69)
list LengthList {
    member: ConB
}
```

was not exercising what it should have, since `ConB`, is its name hints
at, is a constrained structure shape.

* Add changelog entry

Co-authored-by: Julian Antonielli <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Rust server SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants