Skip to content

Commit 91f1ce5

Browse files
Fix return on on_subscribe
1 parent 8a5bcf5 commit 91f1ce5

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

aws_lambda_powertools/event_handler/events_appsync/appsync_events.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import warnings
66
from typing import TYPE_CHECKING, Any
77

8+
from aws_lambda_powertools.event_handler.events_appsync.exceptions import UnauthorizedException
89
from aws_lambda_powertools.event_handler.events_appsync.router import Router
910
from aws_lambda_powertools.utilities.data_classes.appsync_resolver_events_event import AppSyncResolverEventsEvent
1011
from aws_lambda_powertools.warnings import PowertoolsUserWarning
11-
from aws_lambda_powertools.event_handler.events_appsync.exceptions import UnauthorizedException
1212

1313
if TYPE_CHECKING:
1414
from collections.abc import Callable
@@ -153,7 +153,8 @@ def _subscribe_events(self) -> Any:
153153
resolver = self._subscribe_registry.find_resolver(channel_path)
154154
if resolver:
155155
try:
156-
return resolver["func"]()
156+
resolver["func"]()
157+
return None # Must return None in subscribe events
157158
except UnauthorizedException:
158159
raise
159160
except Exception as error:

tests/functional/event_handler/required_dependencies/appsync/test_appsync_events_resolvers.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,7 @@ def test_handler():
15351535
assert "error" in result
15361536
assert "ValueError - Test error" in result["error"]
15371537

1538+
15381539
def test_subscribe_event_with_valid_return(lambda_context, mock_event):
15391540
"""Test error handling during publish event processing."""
15401541
# GIVEN a sample publish event
@@ -1551,8 +1552,9 @@ def test_handler():
15511552
# WHEN we resolve the event
15521553
result = app.resolve(mock_event, lambda_context)
15531554

1554-
# THEN we should get an error response
1555-
assert result == 1
1555+
# THEN we should return None because subscribe always must return None
1556+
assert result is None
1557+
15561558

15571559
def test_subscribe_event_with_no_resolver(lambda_context, mock_event):
15581560
"""Test error handling during publish event processing."""
@@ -1573,6 +1575,7 @@ def test_handler():
15731575
# THEN we should get an error response
15741576
assert not result
15751577

1578+
15761579
def test_publish_events_throw_unauthorized_exception(lambda_context, mock_event):
15771580
"""Test handling events with an empty payload."""
15781581
# GIVEN a sample publish event with empty events
@@ -1593,6 +1596,7 @@ def handle_events(payload):
15931596
with pytest.raises(UnauthorizedException):
15941597
app.resolve(mock_event, lambda_context)
15951598

1599+
15961600
def test_subscribe_events_throw_unauthorized_exception(lambda_context, mock_event):
15971601
"""Test handling events with an empty payload."""
15981602
# GIVEN a sample publish event with empty events

0 commit comments

Comments
 (0)