Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b89f9ad

Browse files
authoredFeb 21, 2024
fix(event-handler): return dict on missing multi_value_headers (#3824)
* fix(parameters): make cache aware of single vs multiple calls Signed-off-by: heitorlessa <[email protected]> * chore: cleanup, add test for single and nested Signed-off-by: heitorlessa <[email protected]> * fix(event-handler): return dict on missing multi_value_headers Signed-off-by: heitorlessa <[email protected]> * chore: default dict for multi query strings too Signed-off-by: heitorlessa <[email protected]> * revert: path_parameters and stage_variables unrelated to the issue --------- Signed-off-by: heitorlessa <[email protected]>
1 parent 812ab3f commit b89f9ad

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed
 

‎aws_lambda_powertools/utilities/data_classes/api_gateway_proxy_event.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ def resource(self) -> str:
112112

113113
@property
114114
def multi_value_headers(self) -> Dict[str, List[str]]:
115-
return self["multiValueHeaders"]
115+
return self.get("multiValueHeaders") or {}
116116

117117
@property
118-
def multi_value_query_string_parameters(self) -> Optional[Dict[str, List[str]]]:
119-
return self.get("multiValueQueryStringParameters")
118+
def multi_value_query_string_parameters(self) -> Dict[str, List[str]]:
119+
return self.get("multiValueQueryStringParameters") or {}
120120

121121
@property
122122
def resolved_query_string_parameters(self) -> Dict[str, List[str]]:

‎tests/functional/event_handler/test_openapi_validation_middleware.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,3 +1108,23 @@ def my_path(
11081108
# THEN the handler should be invoked and return 200
11091109
result = app(gw_event_http, {})
11101110
assert result["statusCode"] == 200
1111+
1112+
1113+
def test_validate_with_minimal_event():
1114+
# GIVEN an APIGatewayRestResolver with validation enabled
1115+
app = APIGatewayRestResolver(enable_validation=True)
1116+
1117+
# WHEN a handler is defined with a default scalar parameter
1118+
@app.get("/users/<user_id>")
1119+
def handler(user_id: int = 123):
1120+
print(user_id)
1121+
1122+
minimal_event = {
1123+
"path": "/users/123",
1124+
"httpMethod": "GET",
1125+
"requestContext": {"requestId": "227b78aa-779d-47d4-a48e-ce62120393b8"}, # correlation ID
1126+
}
1127+
1128+
# THEN the handler should be invoked and return 200
1129+
result = app(minimal_event, {})
1130+
assert result["statusCode"] == 200

0 commit comments

Comments
 (0)
Please sign in to comment.