Skip to content

Fix CI, adapt to new redis-py release #4431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sentry_sdk/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class SDKInfo(TypedDict):
"contexts": dict[str, dict[str, object]],
"dist": str,
"duration": Optional[float],
"environment": str,
"environment": Optional[str],
"errors": list[dict[str, Any]], # TODO: We can expand on this type
"event_id": str,
"exception": dict[
Expand All @@ -188,7 +188,7 @@ class SDKInfo(TypedDict):
"monitor_slug": Optional[str],
"platform": Literal["python"],
"profile": object, # Should be sentry_sdk.profiler.Profile, but we can't import that here due to circular imports
"release": str,
"release": Optional[str],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy was complaining because of environment and release potentially being None here

"request": dict[str, object],
"sdk": Mapping[str, object],
"server_name": str,
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/django/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ async def __acall__(self, *args, **kwargs):
middleware_span = _check_middleware_span(old_method=f)

if middleware_span is None:
return await f(*args, **kwargs)
return await f(*args, **kwargs) # type: ignore

with middleware_span:
return await f(*args, **kwargs)
return await f(*args, **kwargs) # type: ignore

return SentryASGIMixin
10 changes: 9 additions & 1 deletion sentry_sdk/integrations/redis/_async_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ async def _sentry_execute(self, *args, **kwargs):
origin=SPAN_ORIGIN,
) as span:
with capture_internal_exceptions():
try:
command_seq = self._execution_strategy._command_queue
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redis-py PR that introduced this

except AttributeError:
if is_cluster:
command_seq = self._command_stack
else:
command_seq = self.command_stack

set_db_data_fn(span, self)
_set_pipeline_data(
span,
is_cluster,
get_command_args_fn,
False if is_cluster else self.is_transaction,
self._command_stack if is_cluster else self.command_stack,
command_seq,
)

return await old_execute(self, *args, **kwargs)
Expand Down
14 changes: 11 additions & 3 deletions sentry_sdk/integrations/redis/redis_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@ def _set_async_cluster_db_data(span, async_redis_cluster_instance):
def _set_async_cluster_pipeline_db_data(span, async_redis_cluster_pipeline_instance):
# type: (Span, AsyncClusterPipeline[Any]) -> None
with capture_internal_exceptions():
client = getattr(async_redis_cluster_pipeline_instance, "cluster_client", None)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redis-py PR that introduced this

if client is None:
# In older redis-py versions, the AsyncClusterPipeline had a `_client`
# attr but it is private so potentially problematic and mypy does not
# recognize it - see
# https://github.com/redis/redis-py/blame/v5.0.0/redis/asyncio/cluster.py#L1386
client = (
async_redis_cluster_pipeline_instance._client # type: ignore[attr-defined]
)

_set_async_cluster_db_data(
span,
# the AsyncClusterPipeline has always had a `_client` attr but it is private so potentially problematic and mypy
# does not recognize it - see https://github.com/redis/redis-py/blame/v5.0.0/redis/asyncio/cluster.py#L1386
async_redis_cluster_pipeline_instance._client, # type: ignore[attr-defined]
client,
)


Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def sentry_execute_request_handler(self, *args, **kwargs):
else:

@coroutine # type: ignore
def sentry_execute_request_handler(self, *args, **kwargs): # type: ignore
def sentry_execute_request_handler(self, *args, **kwargs):
# type: (RequestHandler, *Any, **Any) -> Any
with _handle_request_impl(self):
result = yield from old_execute(self, *args, **kwargs)
Expand Down
16 changes: 1 addition & 15 deletions tests/integrations/aiohttp/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

import pytest

try:
import pytest_asyncio
except ImportError:
pytest_asyncio = None

from aiohttp import web, ClientSession
from aiohttp.client import ServerDisconnectedError
from aiohttp.web_request import Request
Expand All @@ -27,14 +22,6 @@
from tests.conftest import ApproxDict


if pytest_asyncio is None:
# `loop` was deprecated in `pytest-aiohttp`
# in favor of `event_loop` from `pytest-asyncio`
@pytest.fixture
def event_loop(loop):
yield loop


@pytest.mark.asyncio
async def test_basic(sentry_init, aiohttp_client, capture_events):
sentry_init(integrations=[AioHttpIntegration()])
Expand Down Expand Up @@ -490,7 +477,7 @@ async def hello(request):

@pytest.mark.asyncio
async def test_crumb_capture(
sentry_init, aiohttp_raw_server, aiohttp_client, event_loop, capture_events
sentry_init, aiohttp_raw_server, aiohttp_client, capture_events
):
def before_breadcrumb(crumb, hint):
crumb["data"]["extra"] = "foo"
Expand Down Expand Up @@ -546,7 +533,6 @@ async def test_crumb_capture_client_error(
sentry_init,
aiohttp_raw_server,
aiohttp_client,
event_loop,
capture_events,
status_code,
level,
Expand Down
Loading