From 871fb953eaeeb3d1e86302880bdfd20c7671e6a0 Mon Sep 17 00:00:00 2001 From: Teague Bick Date: Wed, 17 Jul 2024 08:50:56 -0400 Subject: [PATCH] fix (redis): define result for try/catch (#9786) Prior to this change one of the redis_utils functions attempted to call a function in a try/catch with `result=result` with result being defined within the try. This caused "undefined variable" errors to be raised when the exception was hit. After this change, result is initialized as None before the try/catch, preventing the "undefined variable" errors" ## Checklist - [ ] The PR description includes an overview of the change - [ ] The PR description articulates the motivation for the change - [ ] The change includes tests OR the PR description describes a testing strategy - [ ] The PR description notes risks associated with the change, if any - [ ] Newly-added code is easy to change - [ ] The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - [ ] The change includes or references documentation updates if necessary - [ ] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Newly-added code is easy to change - [x] Release note makes sense to a user of the library - [x] If necessary, author has 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) (cherry picked from commit 3d8ba40ad082bff2171a5cf7c1ee1d294f0ade91) --- ddtrace/contrib/redis_utils.py | 1 + .../redis-utils-fix-undefined-variable-6c7d2d5ffcd01b41.yaml | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 releasenotes/notes/redis-utils-fix-undefined-variable-6c7d2d5ffcd01b41.yaml diff --git a/ddtrace/contrib/redis_utils.py b/ddtrace/contrib/redis_utils.py index b6e8623333f..fe9320d15be 100644 --- a/ddtrace/contrib/redis_utils.py +++ b/ddtrace/contrib/redis_utils.py @@ -68,6 +68,7 @@ async def _run_redis_command_async(ctx: core.ExecutionContext, func, args, kwarg parsed_command = stringify_cache_args(args) redis_command = parsed_command.split(" ")[0] rowcount = None + result = None try: result = await func(*args, **kwargs) return result diff --git a/releasenotes/notes/redis-utils-fix-undefined-variable-6c7d2d5ffcd01b41.yaml b/releasenotes/notes/redis-utils-fix-undefined-variable-6c7d2d5ffcd01b41.yaml new file mode 100644 index 00000000000..f5032c366f5 --- /dev/null +++ b/releasenotes/notes/redis-utils-fix-undefined-variable-6c7d2d5ffcd01b41.yaml @@ -0,0 +1,3 @@ +fixes: + - | + redis: This fix resolves an issue in redis utils where a variable may not be declared within a try/catch \ No newline at end of file