Skip to content

Commit 20e73a2

Browse files
Fix side-effect-in-assert in 036 trace.id check
CodeQL py/side-effect-in-assert flagged the expected_metadata.pop() inside the assert: under python -O the assertion (and its pop) is stripped, leaving the invocation_id key in expected_metadata for the later _assert_metadata_subset to wrongly check. Bind the pop to a local before the assert, and include the expected value in the failure message.
1 parent 082f0b6 commit 20e73a2

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

tests/conformance/test_observability_langfuse.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,8 +1270,9 @@ def _assert_trace(
12701270
# real SDK derives trace.id and preserves the raw in metadata; the in-memory
12711271
# recorder keeps the raw AS trace.id, so recover it from there.
12721272
if "invocation_id" in expected_metadata and "invocation_id" not in trace.metadata:
1273-
assert trace.id == expected_metadata.pop("invocation_id"), (
1274-
f"trace.metadata.invocation_id: raw trace.id {trace.id!r} != expected"
1273+
expected_invocation_id = expected_metadata.pop("invocation_id")
1274+
assert trace.id == expected_invocation_id, (
1275+
f"trace.metadata.invocation_id: raw trace.id {trace.id!r} != {expected_invocation_id!r}"
12751276
)
12761277
_assert_metadata_subset("trace.metadata", trace.metadata, expected_metadata)
12771278
# Proposal 0043 (§8.4.1 trace.input/output sourcing). Fixtures that

0 commit comments

Comments
 (0)