-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Update Response Parsing Protocol Tests #3247
base: develop
Are you sure you want to change the base?
Update Response Parsing Protocol Tests #3247
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## develop #3247 +/- ##
==========================================
Coverage ? 93.13%
==========================================
Files ? 66
Lines ? 14428
Branches ? 0
==========================================
Hits ? 13437
Misses ? 991
Partials ? 0 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handful of questions about the current implementation.
cleaned_value = { | ||
k: v for k, v in cleaned_value.items() if v is not None | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand how we're getting to a state where we have None
values arriving here. Do we have an example of what that case might look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rust SDK has experienced issues (aws-sdk-rust#1095) when parsing responses from services like quicksight who populate additional union members with null values. Although the quicksight case doesn't specifically affect boto3 due to differences in modeled shape between Smithy and C2J, it’s possible for any other service to send us this type of response for a union structure.
Related Protocol Test Id: AwsJson10DeserializeAllowNulls
if ( | ||
'location' in member_shape.serialization | ||
location in self.KNOWN_LOCATIONS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What specific test case is this handling? I'm not sure how we'd introduce a new location in a model that's unhandled. This is mostly for my own understanding of what we defined in the protocol tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Request object members can be modeled with location
values that aren't applied to response parsing such as uri
and querystring
. In the case where the same structure is modeled for the input and output of an operation and one of location values mentioned above is modeled, we would incorrectly assume the member has already been handled and fail to parse the related member.
Solution: Add a list (KNOWN_LOCATIONS = ('statusCode', 'header', 'headers')
of know locations used to determine if a member is parsed in a location that is not the body. We'll only skip the member if one of these locations is specified, preventing the case where we unintentionally skip when "location": "uri"
is specified.
Related Protocol Test Id: IgnoreQueryParamsInResponse
@@ -577,7 +590,7 @@ def _do_parse(self, response, shape): | |||
return self._parse_body_as_xml(response, shape, inject_metadata=True) | |||
|
|||
def _parse_body_as_xml(self, response, shape, inject_metadata=True): | |||
xml_contents = response['body'] | |||
xml_contents = response['body'] or b'<xml/>' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there something unique about this case or should this be handled farther down in _parse_xml_string_to_dom
? I'm curious what valid cases we're expecting the service to send us a body and we're getting nothing.
if '#' in code: | ||
code = code.rsplit('#', 1)[1] | ||
code = code.split('#', 1)[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is semantically different. Are we enforcing that the code is everything following the first #
?
if ':' in code: | ||
code = code.split(':', 1)[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are now 3 distinct if
statements here that aren't using elif/else
. Is the intent to continually mutate the code
value as it goes through each check?
e.g.
com.test.mypackage#this:that#1
-- split(':', 1)
--> com.test.mypackage#this
com.test.mypackage#
-- split('#', 1)
--> this
Then this
is evaluated for the x-amzn-query-error
code?
if code is not None: | ||
if ':' in code: | ||
code = code.split(':', 1)[0] | ||
if '#' in code: | ||
code = code.split('#', 1)[1] | ||
error['Error']['Code'] = code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we're changing behavior again here. Is there additional scope, or why are we post-processing the body for the code
case now?
PROTOCOL_TEST_IGNORE_LIST_PATH = os.path.join(TEST_DIR, IGNORE_LIST_FILENAME) | ||
with open(PROTOCOL_TEST_IGNORE_LIST_PATH) as f: | ||
PROTOCOL_TEST_IGNORE_LIST = json.load(f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we use PROTOCOL_TEST_IGNORE_LIST_PATH
somewhere else? Should this whole thing be a self-contained function or pytest
fixture instead?
# If a test case doesn't define a response body, set it to `None`. | ||
if 'body' in case['response']: | ||
body_bytes = case['response']['body'].encode('utf-8') | ||
case['response']['body'] = body_bytes | ||
else: | ||
case['response']['body'] = b'' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are we setting the body to None
? It looks like our fallback is empty bytes. Is this what's causing issues with the xml test above?
@@ -462,7 +503,7 @@ def _get_suite_test_id(): | |||
if len(split) == 2: | |||
suite_id, test_id = int(split[0]), int(split[1]) | |||
else: | |||
suite_id = int(split([0])) | |||
suite_id = int(split[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code even reachable? How did this work before?
@@ -1,612 +1,1847 @@ | |||
[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
high-level question; do we know if the new files cover all the existing cases we're deleting?
* Update ignore list * Resolve some parser issues
57d7547
to
5d9bb32
Compare
cleaned_value = { | ||
k: v for k, v in cleaned_value.items() if v is not None | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rust SDK has experienced issues (aws-sdk-rust#1095) when parsing responses from services like quicksight who populate additional union members with null values. Although the quicksight case doesn't specifically affect boto3 due to differences in modeled shape between Smithy and C2J, it’s possible for any other service to send us this type of response for a union structure.
Related Protocol Test Id: AwsJson10DeserializeAllowNulls
serialized_member_names = [ | ||
shape.members[member].serialization.get('name', member) | ||
for member in shape.members | ||
] | ||
if tag not in serialized_member_names: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When parsing union structure members, botocore will use the raw member name from the HTTP response to determine if the member is know or not. If unknown, the union is populated with the following member:
“SDK_UNKNOWN_MEMBER”: {
“name”: “<unknown member name>”
}
Botocore fails to consider union members modeled with a locationName
which is used to provide an alias for a member’s name.
Solution: When determining if a union member is know, we should consider serialized names for members modeled with the locationName
trait.
Realted Protocol Test Ids: PostUnionWithJsonNameResponse1
, PostUnionWithJsonNameResponse2
Summary
This PR replaces the existing response parsing protocol tests in
botocore/tests/unit/protocols/output
with new tests generated from Smithy protocol test models. We use a version of these Smithy tests that are converted to the format currently supported by our existing test runner (test_protocols.py
). This PR makes updates to the botocore Parsers and protocol test runner to comply with a majority of the new test cases.Granular Protocol Ignore List
This PR introduces a
protocol-tests-ignore-list.json
file that can be used to ignore specific protocol test suites or cases.The structure for this list is defined below:
<test_type>
- There are two types of protocol tests.input
- Request serialization protocol test.output
- Response parsing protocol test.output
will work until the request serialization tests are updated.suites
- A list of test suite descriptions to ignore. When specified, all test cases for the related suite will be ignored.cases
- A list of test case ids to ignore.<protocol_name>
- The protocol name as represented by its corresponding protocol test file name (without the.json
) extension.ec2
,json
,json_1_0
,query
,rest-json
,rest-xml
. This may grow as we add more protocols.