Skip to content

Commit 5a1db78

Browse files
authored
Merge branch 'develop' into fix/1153-exception-handler-raises
2 parents 260d36d + c92bde6 commit 5a1db78

File tree

9 files changed

+107
-69
lines changed

9 files changed

+107
-69
lines changed

.github/mergify.yml

+29-27
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
queue_rules:
2-
- name: default
3-
conditions:
4-
# Conditions to get out of the queue (= merged)
5-
- check-success=Semantic Pull Request
6-
- "#approved-reviews-by>=1"
7-
- -title~=(WIP|wip)
8-
- -label~="do-not-merge"
9-
- "#changes-requested-reviews-by=0"
1+
## Temporarily disabled after Mergify breaking changes
2+
## might move to custom GitHub Actions altogether
3+
# queue_rules:
4+
# - name: default
5+
# conditions:
6+
# # Conditions to get out of the queue (= merged)
7+
# - check-success=Semantic Pull Request
8+
# - "#approved-reviews-by>=1"
9+
# - -title~=(WIP|wip)
10+
# - -label~="do-not-merge"
11+
# - "#changes-requested-reviews-by=0"
1012

11-
pull_request_rules:
12-
- name: automatic merge for Dependabot pull requests
13-
conditions:
14-
- author~=^dependabot(|-preview)\[bot\]$
15-
actions:
16-
queue:
17-
name: default
18-
method: squash
19-
commit_message: title+body
13+
# pull_request_rules:
14+
# - name: automatic merge for Dependabot pull requests
15+
# conditions:
16+
# - author~=^dependabot(|-preview)\[bot\]$
17+
# actions:
18+
# queue:
19+
# name: default
20+
# method: squash
21+
# commit_message: title+body
2022

21-
- name: Automatic merge ⬇️ on approval ✔
22-
conditions:
23-
- base!=master
24-
- "#approved-reviews-by>=2"
25-
actions:
26-
queue:
27-
name: default
28-
method: squash
29-
commit_message: title+body
23+
# - name: Automatic merge ⬇️ on approval ✔
24+
# conditions:
25+
# - base!=master
26+
# - "#approved-reviews-by>=2"
27+
# actions:
28+
# queue:
29+
# name: default
30+
# method: squash
31+
# commit_message: title+body

.github/workflows/codeql-analysis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424

2525
# Initializes the CodeQL tools for scanning.
2626
- name: Initialize CodeQL
27-
uses: github/codeql-action/init@v1
27+
uses: github/codeql-action/init@v2
2828
with:
2929
languages: ${{ matrix.language }}
3030
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -33,4 +33,4 @@ jobs:
3333
# queries: ./path/to/local/query, your-org/your-repo/queries@main
3434

3535
- name: Perform CodeQL Analysis
36-
uses: github/codeql-action/analyze@v1
36+
uses: github/codeql-action/analyze@v2

.github/workflows/post_release.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const fetchIssues = async ({
1515
gh_client,
1616
org,
1717
repository,
18-
state = "open",
18+
state = "all",
1919
label = STAGED_LABEL,
2020
}) => {
2121

aws_lambda_powertools/event_handler/api_gateway.py

+5
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,11 @@ def resolve(self, event, context) -> Dict[str, Any]:
491491
dict
492492
Returns the dict response
493493
"""
494+
if isinstance(event, BaseProxyEvent):
495+
warnings.warn(
496+
"You don't need to serialize event to Event Source Data Class when using Event Handler; see issue #1152"
497+
)
498+
event = event.raw_event
494499
if self._debug:
495500
print(self._json_dump(event), end="")
496501
BaseRouter.current_event = self._to_proxy_event(event)

aws_lambda_powertools/utilities/batch/sqs.py

+4
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ def _clean(self) -> Optional[List]:
135135
return None
136136

137137
queue_url = self._get_queue_url()
138+
if queue_url is None:
139+
logger.debug("No queue url found")
140+
return None
141+
138142
entries_to_remove = self._get_entries_to_clean()
139143
# Batch delete up to 10 messages at a time (SQS limit)
140144
max_workers = math.ceil(len(entries_to_remove) / self.max_message_batch)

aws_lambda_powertools/utilities/idempotency/persistence/dynamodb.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(
2222
self,
2323
table_name: str,
2424
key_attr: str = "id",
25-
static_pk_value: str = f"idempotency#{os.getenv(constants.LAMBDA_FUNCTION_NAME_ENV, '')}",
25+
static_pk_value: Optional[str] = None,
2626
sort_key_attr: Optional[str] = None,
2727
expiry_attr: str = "expiration",
2828
status_attr: str = "status",
@@ -76,6 +76,9 @@ def __init__(
7676
if sort_key_attr == key_attr:
7777
raise ValueError(f"key_attr [{key_attr}] and sort_key_attr [{sort_key_attr}] cannot be the same!")
7878

79+
if static_pk_value is None:
80+
static_pk_value = f"idempotency#{os.getenv(constants.LAMBDA_FUNCTION_NAME_ENV, '')}"
81+
7982
self._table = None
8083
self.table_name = table_name
8184
self.key_attr = key_attr

poetry.lock

+32-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ pytest-asyncio = "^0.16.0"
4949
bandit = "^1.7.1"
5050
radon = "^5.1.0"
5151
xenon = "^0.9.0"
52-
flake8-eradicate = "^1.2.0"
53-
flake8-bugbear = "^22.1.11"
52+
flake8-eradicate = "^1.2.1"
53+
flake8-bugbear = "^22.4.25"
5454
mkdocs-git-revision-date-plugin = "^0.3.2"
5555
mike = "^0.6.0"
56-
mypy = "^0.942"
56+
mypy = "^0.950"
5757
mkdocs-material = "^8.2.7"
5858

5959

tests/functional/event_handler/test_api_gateway.py

+27-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131
)
3232
from aws_lambda_powertools.shared import constants
3333
from aws_lambda_powertools.shared.json_encoder import Encoder
34-
from aws_lambda_powertools.utilities.data_classes import ALBEvent, APIGatewayProxyEvent, APIGatewayProxyEventV2
34+
from aws_lambda_powertools.utilities.data_classes import (
35+
ALBEvent,
36+
APIGatewayProxyEvent,
37+
APIGatewayProxyEventV2,
38+
event_source,
39+
)
3540
from tests.functional.utils import load_event
3641

3742

@@ -1213,8 +1218,7 @@ def handle_not_found(_) -> Response:
12131218

12141219

12151220
def test_exception_handler_raises_service_error(json_dump):
1216-
# SCENARIO: Support an exception_handler that raises a ServiceError
1217-
# GIVEN
1221+
# GIVEN an exception handler raises a ServiceError (BadRequestError)
12181222
app = ApiGatewayResolver()
12191223

12201224
@app.exception_handler(ValueError)
@@ -1234,3 +1238,23 @@ def get_lambda() -> Response:
12341238
assert result["headers"]["Content-Type"] == content_types.APPLICATION_JSON
12351239
expected = {"statusCode": 400, "message": "Bad request"}
12361240
assert result["body"] == json_dump(expected)
1241+
1242+
1243+
def test_event_source_compatibility():
1244+
# GIVEN
1245+
app = APIGatewayHttpResolver()
1246+
1247+
@app.post("/my/path")
1248+
def my_path():
1249+
assert isinstance(app.current_event, APIGatewayProxyEventV2)
1250+
return {}
1251+
1252+
# WHEN
1253+
@event_source(data_class=APIGatewayProxyEventV2)
1254+
def handler(event: APIGatewayProxyEventV2, context):
1255+
assert isinstance(event, APIGatewayProxyEventV2)
1256+
return app.resolve(event, context)
1257+
1258+
# THEN
1259+
result = handler(load_event("apiGatewayProxyV2Event.json"), None)
1260+
assert result["statusCode"] == 200

0 commit comments

Comments
 (0)