From 4115cbb60efcfebb06bea33ab208d1f9703aca1f Mon Sep 17 00:00:00 2001 From: Thomas Pierce Date: Fri, 20 Mar 2026 09:34:36 -0700 Subject: [PATCH] fix: unwrap() broken on wrapt 2.x due to ObjectProxy class identity mismatch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In wrapt 2.x, wrapt.ObjectProxy points to wrapt.proxies.ObjectProxy (pure Python) while FunctionWrapper inherits from a different ObjectProxy in the C extension (_wrappers.so). This causes isinstance(f, wrapt.ObjectProxy) to return False, making unwrap() a silent no-op. Since unwrap() never actually unwraps, each patch/unpatch cycle in the test fixture accumulates another wrapper layer. By the 5th test (test_invalid_url), there are 5 nested wrappers creating 5 nested subsegments — only the innermost gets the real exception dict, outer ones get string cause IDs. Fix: remove the isinstance check from unwrap() — hasattr(f, '__wrapped__') is sufficient to identify wrapt-wrapped functions. This also fixes a user-facing bug: any application calling unpatch()/patch() (e.g. during reconfiguration) would accumulate wrapper layers, causing subsegment bloat on every patched call. Affects all ext modules using unwrap(), not just httplib. --- aws_xray_sdk/ext/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_xray_sdk/ext/util.py b/aws_xray_sdk/ext/util.py index 0c67e537..fb1d7211 100644 --- a/aws_xray_sdk/ext/util.py +++ b/aws_xray_sdk/ext/util.py @@ -135,5 +135,5 @@ def unwrap(obj, attr): :param attr: attribute on `obj` to unwrap """ f = getattr(obj, attr, None) - if f and isinstance(f, wrapt.ObjectProxy) and hasattr(f, '__wrapped__'): + if f and hasattr(f, '__wrapped__'): setattr(obj, attr, f.__wrapped__)