Fix AttributeError in cluster metrics recording when connection is None or ClusterNode object instance is used to extract the connection info#3999
Merged
petyaslavova merged 2 commits intomasterfrom Mar 16, 2026
Conversation
…ne or ClusterNode object instance is used to extract the connection info
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
vladvildanov
approved these changes
Mar 12, 2026
petyaslavova
added a commit
that referenced
this pull request
Mar 23, 2026
…ne or ClusterNode object instance is used to extract the connection info (#3999)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix AttributeError in cluster metrics recording when connection is None
When exceptions occur in RedisCluster before a connection is established
(e.g., AuthenticationError, MaxConnectionsError), the connection variable
is None or a ClusterNode object (which lacks a 'db' attribute). This caused
AttributeError when recording metrics.
Changes:
variable for metrics recording in exception handlers
Fixes #3997
Note
Medium Risk
Touches Redis Cluster command execution error paths and observability hooks; functional behavior should be unchanged but regressions could affect error handling/metrics accuracy during connection establishment failures.
Overview
Prevents
AttributeErrorduring Redis Cluster observability by consistently recording command duration metrics usinge.connection(which may be aClusterNodefallback) across exception handlers, includingAuthenticationError,MaxConnectionsError, and connection/timeout-related failures.Makes
_record_command_metricdefensive whenconnectionisNoneor lacksdb, defaulting host/port/db to safe values, and expands tests to cover sync and asyncio cluster scenarios for these error cases and successful metric recording with a non-default DB.Written by Cursor Bugbot for commit bc9ddb4. This will update automatically on new commits. Configure here.