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 marker trait for numeric shapes that should be serialized even when equal to 0 #1830

Closed
wants to merge 4 commits into from

Conversation

Velfi
Copy link
Contributor

@Velfi Velfi commented Oct 7, 2022

Motivation and Context

aws-sdk-rust#630

Description

update: serializer generation to serialize zero values for shapes with the SerializeZeroValues trait
fix: bug that occurs when serializing a "com.amazonaws.s3#ScanRange" starting at zero
add: SerializeZeroValues smithy trait
update: unify names of serializerUtil vars in serializer codegen
update: CHANGELOG.next.toml with release notes

Testing

I verified that this change fixes the bug and included an integration test.

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.

…h the SerializeZeroValues trait

fix: bug that occurs when serializing a "com.amazonaws.s3#ScanRange" starting at zero
add: SerializeZeroValues smithy trait
update: unify names of serializerUtil vars in serializer codegen
update: CHANGELOG.next.toml with release notes
@github-actions
Copy link

github-actions bot commented Oct 7, 2022

A new generated diff is ready to view.

A new doc preview is ready to view.

add: missing copyright header
format: run ktlint
@github-actions
Copy link

github-actions bot commented Oct 7, 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 Oct 7, 2022

A new generated diff is ready to view.

A new doc preview is ready to view.

@david-perez
Copy link
Contributor

david-perez commented Oct 7, 2022

I've recently looked at this part of the codebase to fix #1831.

Why are we not serializing zero values? I was able to trace the introduction of this behavior to #439. We're enforcing it via tests in restXml:

https://github.com/awslabs/smithy-rs/blob/e78da5598a2d94d23fd18e30492a20ce3603f844/codegen-client-test/model/rest-xml-extras.smithy#L38-L63

And restJson1:

https://github.com/awslabs/smithy-rs/blob/e78da5598a2d94d23fd18e30492a20ce3603f844/codegen-core/common-test-models/rest-json-extras.smithy#L117-L126

These tests are part of our "extras" suites; I can't find mention of this behavior in the official AWS specs.

To me this seems really odd. The server is also reusing the serializers, so it's also not serializing zero values in responses.

private val serializeZeroValuesAllowList = setOf(
// Omitting this when zero would change the meaning of the range.
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_ScanRange.html
ShapeId.from("com.amazonaws.s3#Start"),
Copy link

Choose a reason for hiding this comment

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

I believe End should also accept zero.

https://docs.aws.amazon.com/AmazonS3/latest/API/API_ScanRange.html#AmazonS3-Type-ScanRange-End

[~] aws s3api select-object-content \
--bucket ${BUCKET_NAME_OMMITED} \
--key data-1m.json \
--expression 'SELECT * FROM s3object s' \
--expression-type SQL \
--input-serialization '{"JSON": {"Type": "LINES"}, "CompressionType": "NONE"}' \
--output-serialization '{"JSON": {}}' \
--scan-range Start=0,End=0 \
0.json
[~] echo $?
0
[~] cat 0.json
{"a":"foo","b":1,"c":"aaa"}

@Licht-T
Copy link

Licht-T commented Oct 7, 2022

I briefly looked into the smithy-rs code base and found that it sometimes uses zero as an optional value, which means not-inputted. Also, I took a look at other SDKs, and they are handling a not-inputted as null.

I think this is the structural problem, and, in the long term, smithy-rs should handle a not-inputted as Option.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@jdisanti
Copy link
Collaborator

I think the larger fix that needs to happen is input tracking. Any value provided by a customer must be serialized and sent, regardless if it's zero value or not. It's hard to say why omitting the zero value was implemented since the commit doesn't provide any reasoning. I also didn't see any information about it in the Smithy specs.

@david-perez - What's the expected behavior for server side serialization? Is it compatible with input tracking (output tracking in the server case)?

@david-perez
Copy link
Contributor

No problems server-side on implementing input/output tracking.

Omitting serialization of values (even if they're the default for a type) is even called out as something we should not do in the server in the spec:

Authoritative model consumers like servers SHOULD always serialize default values to remove any ambiguity about the value of the most up to default value.

@Velfi
Copy link
Contributor Author

Velfi commented Oct 27, 2022

I spoke with @rcoh about this and he thinks it should be solved by boxing primitive fields for S3 models. I can look into this after I complete my current task

@Velfi
Copy link
Contributor Author

Velfi commented Oct 27, 2022

Closing in favor of an alternate solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants