From 52519799f721f3a209828399a010766971eaa6e2 Mon Sep 17 00:00:00 2001 From: Joey Zhao <5253430+joeyzhao2018@users.noreply.github.com> Date: Wed, 11 Jun 2025 09:18:40 -0400 Subject: [PATCH] handle a case where the record is some customized item --- datadog_lambda/trigger.py | 2 +- tests/test_trigger.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/datadog_lambda/trigger.py b/datadog_lambda/trigger.py index 14cb06ac..bbd0d027 100644 --- a/datadog_lambda/trigger.py +++ b/datadog_lambda/trigger.py @@ -153,7 +153,7 @@ def parse_event_source(event: dict) -> _EventSource: event_source = _EventSource(EventTypes.STEPFUNCTIONS) event_record = get_first_record(event) - if event_record: + if event_record and isinstance(event_record, dict): aws_event_source = event_record.get("eventSource") or event_record.get( "EventSource" ) diff --git a/tests/test_trigger.py b/tests/test_trigger.py index c12e8f5c..15103937 100644 --- a/tests/test_trigger.py +++ b/tests/test_trigger.py @@ -280,6 +280,13 @@ def test_detect_lambda_function_url_domain_with_invalid_input(self): # Test with string that would normally cause an exception when split self.assertFalse(detect_lambda_function_url_domain("")) + def test_event_source_with_non_dict_event_record(self): + # Test with event_record that's not a dictionary + event = {"Records": "not_a_dict"} + event_source = parse_event_source(event) + # Should handle the first non-dict record gracefully and return unknown + self.assertEqual(event_source.to_string(), "unknown") + class GetTriggerTags(unittest.TestCase): def test_extract_trigger_tags_api_gateway(self):