test: Mock attributes in redis cluster tests - #7022
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 54ca4d2. Configure here.
| redis.RedisCluster.pipeline = lambda *_, **__: pipeline_cls( | ||
| MagicMock(), MagicMock() | ||
| ) | ||
| redis.RedisCluster.get_default_node = lambda *_, **__: redis.cluster.ClusterNode( |
There was a problem hiding this comment.
Bug: The sync Redis ClusterPipeline integration passes the pipeline instance to _set_cluster_db_data instead of the cluster client, causing a silently-suppressed AttributeError and missing span data.
Severity: MEDIUM
Suggested Fix
Create a new wrapper function for the sync case, similar to _set_async_cluster_pipeline_db_data. This function should extract the RedisCluster client from the ClusterPipeline instance and then pass the client to _set_cluster_db_data. Update the patch_redis_pipeline call for cluster.ClusterPipeline to use this new wrapper function as its set_db_data_fn.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: tests/integrations/redis/cluster/test_redis_cluster.py#L22
Potential issue: In the synchronous Redis cluster pipeline integration, the
`patch_redis_pipeline` function incorrectly passes the `ClusterPipeline` instance itself
to the `_set_cluster_db_data` function. This function expects a `RedisCluster` instance
to fetch connection details. When it calls `get_default_node()` on the pipeline object,
an `AttributeError` occurs. This error is silently caught by
`capture_internal_exceptions()`, resulting in the failure to add database connection
metadata (host, port) to the corresponding APM spans. This issue does not occur in the
async implementation, which correctly extracts the client from the pipeline before
gathering data.
Did we get this right? 👍 / 👎 to inform future reviews.
Codecov Results 📊✅ 95086 passed | ⏭️ 6239 skipped | Total: 101325 | Pass Rate: 93.84% | Execution Time: 343m 52s 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 2513 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 89.88% 89.88% —%
==========================================
Files 193 193 —
Lines 24834 24834 —
Branches 8912 8912 —
==========================================
+ Hits 22321 22321 —
- Misses 2513 2513 —
- Partials 1417 1417 —Generated by Codecov Action |
### Description Redis started accessing an internal attribute on the Pipeline class, which threw an `AttributeError` in our tests since we were not mocking the class fully. Also, set up `pytest-asyncio` in Python 3.14 so that we can run async tests. #### Issues Closes getsentry#6974 #### Reminders - Please add tests to validate your changes, and lint your code using `uv run ruff`. - Add GH Issue ID _&_ Linear ID (if applicable) - PR title should use [conventional commit](https://develop.sentry.dev/engineering-practices/commit-messages/#type) style (`feat:`, `fix:`, `ref:`, `meta:`) - For external contributors: [CONTRIBUTING.md](https://github.com/getsentry/sentry-python/blob/master/CONTRIBUTING.md), [Sentry SDK development docs](https://develop.sentry.dev/sdk/), [Discord community](https://discord.gg/Ww9hbqr)

Description
Redis started accessing an internal attribute on the Pipeline class, which threw an
AttributeErrorin our tests since we were not mocking the class fully.Also, set up
pytest-asyncioin Python 3.14 so that we can run async tests.Issues
Closes #6974
Reminders
uv run ruff.feat:,fix:,ref:,meta:)