Skip to content

Commit e230d94

Browse files
authored
handle a case where the record is some customized item (#616)
1 parent b3cf1c2 commit e230d94

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

datadog_lambda/trigger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def parse_event_source(event: dict) -> _EventSource:
153153
event_source = _EventSource(EventTypes.STEPFUNCTIONS)
154154

155155
event_record = get_first_record(event)
156-
if event_record:
156+
if event_record and isinstance(event_record, dict):
157157
aws_event_source = event_record.get("eventSource") or event_record.get(
158158
"EventSource"
159159
)

tests/test_trigger.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,13 @@ def test_detect_lambda_function_url_domain_with_invalid_input(self):
280280
# Test with string that would normally cause an exception when split
281281
self.assertFalse(detect_lambda_function_url_domain(""))
282282

283+
def test_event_source_with_non_dict_event_record(self):
284+
# Test with event_record that's not a dictionary
285+
event = {"Records": "not_a_dict"}
286+
event_source = parse_event_source(event)
287+
# Should handle the first non-dict record gracefully and return unknown
288+
self.assertEqual(event_source.to_string(), "unknown")
289+
283290

284291
class GetTriggerTags(unittest.TestCase):
285292
def test_extract_trigger_tags_api_gateway(self):

0 commit comments

Comments
 (0)