Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "bugfix",
"description": "Fixed awsQuery response deserialization for operations with no output members."
}
10 changes: 7 additions & 3 deletions packages/smithy-aws-core/src/smithy_aws_core/aio/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,14 @@ def _action_name(
def _response_wrapper_elements(
self,
operation: APIOperation[SerializeableShape, DeserializeableShape],
) -> tuple[str, str]:
) -> tuple[str, ...]:
name = operation.schema.id.name
# Operations with no output members will omit the <OpResult> element.
if not operation.output_schema.members:
return (f"{name}Response",)
return (
f"{operation.schema.id.name}Response",
f"{operation.schema.id.name}Result",
f"{name}Response",
f"{name}Result",
)

def _error_wrapper_elements(self) -> tuple[str, ...]:
Expand Down
42 changes: 42 additions & 0 deletions packages/smithy-aws-core/tests/unit/aio/test_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ def test_aws_json_document_discriminator(
],
members={"message": {"target": STRING}},
)
_EMPTY_OUTPUT_SCHEMA = Schema.collection(
id=ShapeID("com.test#EmptyOutput"),
)


@dataclass
Expand Down Expand Up @@ -160,6 +163,16 @@ def _consumer(schema: Schema, de: ShapeDeserializer) -> None:
return cls(**kwargs)


class _EmptyOutput:
@classmethod
def deserialize(cls, deserializer: ShapeDeserializer) -> "_EmptyOutput":
def _consumer(schema: Schema, de: ShapeDeserializer) -> None:
pass

deserializer.read_struct(_EMPTY_OUTPUT_SCHEMA, consumer=_consumer)
return cls()


def _operation_schema(name: str) -> Schema:
return Schema(
id=ShapeID(f"com.test#{name}"),
Expand All @@ -171,10 +184,14 @@ def _mock_operation(
schema: Schema,
*,
error_schemas: list[Schema] | None = None,
output: Any = None,
output_schema: Schema | None = None,
) -> APIOperation[Any, Any]:
operation = Mock(spec=APIOperation)
operation.schema = schema
operation.error_schemas = error_schemas or []
operation.output = output
operation.output_schema = output_schema
return cast("APIOperation[Any, Any]", operation)


Expand Down Expand Up @@ -272,3 +289,28 @@ async def test_aws_query_returns_generic_error_for_unknown_code() -> None:
"Unknown error for operation com.test#FailingOperation"
" - status: 500, code: UnknownThing"
)


async def test_aws_query_deserializes_empty_output_without_result_wrapper() -> None:
protocol = AwsQueryClientProtocol(_SERVICE_SCHEMA, "2020-01-08")
result = await protocol.deserialize_response(
operation=_mock_operation(
_operation_schema("EmptyOperation"),
output=_EmptyOutput,
output_schema=_EMPTY_OUTPUT_SCHEMA,
),
request=cast(HTTPRequest, Mock()),
response=HTTPResponse(
status=200,
fields=tuples_to_fields([]),
body=(
b"<EmptyOperationResponse>"
b"<ResponseMetadata><RequestId>abc-123</RequestId></ResponseMetadata>"
b"</EmptyOperationResponse>"
),
),
error_registry=TypeRegistry({}),
context=TypedProperties(),
)

assert isinstance(result, _EmptyOutput)
Loading