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

add support for nullable struct members when generating AWS SDKs #2916

Merged
merged 43 commits into from
Sep 21, 2023

Conversation

Velfi
Copy link
Contributor

@Velfi Velfi commented Aug 10, 2023

Motivation and Context

smithy-rs#1767 aws-sdk-rust#536

Description

This PR adds support for nullability i.e. much less unwraps will be required when using the AWS SDK. For generic clients, this new behavior can be enabled in codegen by setting nullabilityCheckMode: "Client" in their codegen config:

      "plugins": {
        "rust-client-codegen": {
          "codegen": {
            "includeFluentClient": false,
            "nullabilityCheckMode": "CLIENT_CAREFUL"
          },
     }

Testing

Ran existing tests

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the smithy-rs codegen or runtime crates
  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

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

@Velfi Velfi requested review from a team as code owners August 10, 2023 19:37
@github-actions
Copy link

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.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@Velfi Velfi added the breaking-change This will require a breaking change label Aug 14, 2023
@github-actions
Copy link

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.

@rcoh
Copy link
Collaborator

rcoh commented Aug 15, 2023

I think we should also note that certain fields are required in the generated docs

Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so excited about this!

Comment on lines +169 to +180
val errorMessageMember = errorShape.errorMessageMember()
// If the message member is optional and wasn't set, we set a generic error message.
if (errorMessageMember != null) {
if (errorMessageMember.isOptional) {
rust(
"""
if tmp.message.is_none() {
tmp.message = _error_message;
}
""",
)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this dropping it if it's not optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, this code is meant to set an error message. When the message is optional and wasn't provided, we set a generic message. This code isn't relevant when the message is required, as we can count on one being included in the response.

} else {
rust("Ok(Some(builder.build()))")
if (hasFallibleBuilder(shape, symbolProvider)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be if (hasFaillibleBuilder || !returnSymbolToParse.isUnconstrained)?

Alternatively, can we push returnSymbolToParse as an argument to hasFallibleBuilder? That might help us make sure we caught all of these locations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how the logic can be simplified that way. I also don't see how passing returnSymbolToParse as an argument to hasFallibleBuilder simplifies things. returnSymbolToParse is about whether we should parse a value for a shape into its associated unconstrained type. In the client this is always false because it has no notion of constraint traits.

Comment on lines 39 to 40
message = "Struct members modeled as required are no longer wrapped in `Option`s."
references = ["smithy-rs#2916", "aws-sdk-rust#536"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upgrade guidance would be helpful (it's simple but just listing it out is probably handy.)

An FAQ for why some members are still not optional would also be helpful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done #2929

return;
}
}
}

pub(crate) struct Route53ResourceIdInterceptor<G, T>
where
G: for<'a> Fn(&'a mut T) -> &'a mut Option<String>,
G: for<'a> Fn(&'a mut T) -> Option<&'a mut String>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side note, might be nice to replace these existential types with a trait for clarity

Comment on lines 48 to +53
.attribute_definitions(
AttributeDefinition::builder()
.attribute_name("title")
.attribute_type(ScalarAttributeType::S)
.build(),
.build()
.unwrap(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side note: I wonder if we want this API to accept impl TryInto<AttributeDefinitions>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put another way, what if users could pass a builder directly?

rust-runtime/aws-smithy-http/src/operation/error.rs Outdated Show resolved Hide resolved
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

update code in response to PR comments
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Velfi added 2 commits August 16, 2023 14:00
update serde tests to cover more cases
Copy link
Contributor

@david-perez david-perez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the PR description needs to be updated. The option is nullabilityCheckMode.

@rcoh rcoh force-pushed the zhessler-nullability-now! branch from a20dc37 to 99de898 Compare September 21, 2023 14:10
@github-actions
Copy link

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.

Comment on lines +31 to +32
.build()
.unwrap(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change build to try_build and add a build that panics?

@rcoh rcoh added this pull request to the merge queue Sep 21, 2023
Merged via the queue into main with commit 1331dc5 Sep 21, 2023
40 of 41 checks passed
@rcoh rcoh deleted the zhessler-nullability-now! branch September 21, 2023 17:42
DavidSouther added a commit to DavidSouther/aws-doc-sdk-examples that referenced this pull request Sep 27, 2023
DavidSouther added a commit to DavidSouther/aws-doc-sdk-examples that referenced this pull request Sep 28, 2023
DavidSouther added a commit to DavidSouther/aws-doc-sdk-examples that referenced this pull request Sep 28, 2023
DavidSouther added a commit to DavidSouther/aws-doc-sdk-examples that referenced this pull request Sep 29, 2023
Switch to sdk branch = next
Handle nullability change for smithy-lang/smithy-rs#2916
Handle nullability change for smithy-lang/smithy-rs#2995
DavidSouther added a commit to DavidSouther/aws-doc-sdk-examples that referenced this pull request Sep 29, 2023
Switch to sdk branch = next
Handle nullability change for smithy-lang/smithy-rs#2916
Handle nullability change for smithy-lang/smithy-rs#2995
DavidSouther added a commit to DavidSouther/aws-doc-sdk-examples that referenced this pull request Sep 29, 2023
Switch to sdk branch = next
Handle nullability change for smithy-lang/smithy-rs#2916
Handle nullability change for smithy-lang/smithy-rs#2995
meyertst-aws pushed a commit to DavidSouther/aws-doc-sdk-examples that referenced this pull request Sep 29, 2023
Switch to sdk branch = next
Handle nullability change for smithy-lang/smithy-rs#2916
Handle nullability change for smithy-lang/smithy-rs#2995
DavidSouther added a commit to DavidSouther/aws-doc-sdk-examples that referenced this pull request Oct 3, 2023
Switch to sdk branch = next
Handle nullability change for smithy-lang/smithy-rs#2916
Handle nullability change for smithy-lang/smithy-rs#2995
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change This will require a breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants