From 49523e494304555c66e3cabbee61cafbc65730d4 Mon Sep 17 00:00:00 2001 From: Christophe Papazian Date: Wed, 19 Nov 2025 12:59:05 +0100 Subject: [PATCH 1/2] chore(aap): improve internal api protocol --- ddtrace/appsec/_utils.py | 2 +- ddtrace/internal/utils/__init__.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ddtrace/appsec/_utils.py b/ddtrace/appsec/_utils.py index 5f0fee4f54f..083b18b1172 100644 --- a/ddtrace/appsec/_utils.py +++ b/ddtrace/appsec/_utils.py @@ -173,7 +173,7 @@ def __init__( self.location = location.replace(APPSEC.SECURITY_RESPONSE_ID, security_response_id) self.content_type: str = "application/json" - def get(self, method_name: str, default: Any = None) -> Any: + def get(self, method_name: str, default: Any = None) -> Union[str, int]: """ Dictionary-like get method for backward compatibility with Lambda integration. diff --git a/ddtrace/internal/utils/__init__.py b/ddtrace/internal/utils/__init__.py index e5bf0862851..ac3678c49ae 100644 --- a/ddtrace/internal/utils/__init__.py +++ b/ddtrace/internal/utils/__init__.py @@ -87,6 +87,9 @@ class Block_config(Protocol): location: str content_type: str + def get(self, method_name: str, default: Any = None) -> Union[str, int]: + ... + def get_blocked() -> Optional[Block_config]: # local import to avoid circular dependency From 53b333dfdd520e6f100c84864eb9e1394dac2a1f Mon Sep 17 00:00:00 2001 From: Christophe Papazian Date: Thu, 20 Nov 2025 11:34:42 +0100 Subject: [PATCH 2/2] improve compatibility --- ddtrace/appsec/_utils.py | 16 ++++++++++++++-- ddtrace/internal/utils/__init__.py | 7 +++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ddtrace/appsec/_utils.py b/ddtrace/appsec/_utils.py index 083b18b1172..5ea7ac1475f 100644 --- a/ddtrace/appsec/_utils.py +++ b/ddtrace/appsec/_utils.py @@ -173,14 +173,26 @@ def __init__( self.location = location.replace(APPSEC.SECURITY_RESPONSE_ID, security_response_id) self.content_type: str = "application/json" - def get(self, method_name: str, default: Any = None) -> Union[str, int]: + def get(self, key: str, default: Any = None) -> Union[str, int]: """ Dictionary-like get method for backward compatibility with Lambda integration. Returns the attribute value if it exists, otherwise returns the default value. This allows Block_config to be used in contexts that expect dictionary-like access. """ - return getattr(self, method_name, default) + if key == "content-type": + key = "content_type" + return getattr(self, key, default) + + def __getitem__(self, key: str) -> Optional[Union[str, int]]: + if key == "content-type": + key = "content_type" + return getattr(self, key, None) + + def __contains__(self, key: str) -> bool: + if key == "content-type": + key = "content_type" + return bool(getattr(self, key, None)) class Telemetry_result: diff --git a/ddtrace/internal/utils/__init__.py b/ddtrace/internal/utils/__init__.py index ac3678c49ae..fbaac5a684b 100644 --- a/ddtrace/internal/utils/__init__.py +++ b/ddtrace/internal/utils/__init__.py @@ -87,8 +87,11 @@ class Block_config(Protocol): location: str content_type: str - def get(self, method_name: str, default: Any = None) -> Union[str, int]: - ... + def get(self, key: str, default: Any = None) -> Union[str, int]: ... + + def __getitem__(self, key: str) -> Optional[Union[str, int]]: ... + + def __contains__(self, key: str) -> bool: ... def get_blocked() -> Optional[Block_config]: