Skip to content

Commit d4e248a

Browse files
fix(debugging): handle null literal in expressions [backport 1.17] (#6438)
Backport ddd392e from #6388 to 1.17. Make sure that we can handle the null literal in the expression language. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) Co-authored-by: Gabriele N. Tornetta <[email protected]>
1 parent eea10dc commit d4e248a

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

ddtrace/debugging/_expressions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ def _compile_operation(ast):
292292

293293
def _compile_literal(ast):
294294
# type: (DDASTType) -> Optional[List[Instr]]
295-
# literal => <number> | true | false | "string"
296-
if not isinstance(ast, (str, int, float, bool)):
295+
# literal => <number> | true | false | "string" | null
296+
if not (isinstance(ast, (str, int, float, bool)) or ast is None):
297297
return None
298298

299299
return [Instr("LOAD_CONST", ast)]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
dynamic instrumentation: handle null literal in conditions and expressions.

tests/debugging/test_expressions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def __getitem__(self, name):
7272
# Test argument predicates and operations
7373
({"contains": [{"ref": "payload"}, "hello"]}, {"payload": "hello world"}, True),
7474
({"eq": [{"ref": "hits"}, True]}, {"hits": True}, True),
75+
({"eq": [{"ref": "hits"}, None]}, {"hits": None}, True),
7576
({"substring": [{"ref": "payload"}, 4, 7]}, {"payload": "hello world"}, "hello world"[4:7]),
7677
({"any": [{"ref": "collection"}, {"isEmpty": {"ref": "@it"}}]}, {"collection": ["foo", "bar", ""]}, True),
7778
({"startsWith": [{"ref": "local_string"}, "hello"]}, {"local_string": "hello world!"}, True),

0 commit comments

Comments
 (0)