Skip to content

fix(django): Proper transaction names for i18n routes #3104

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 5 commits into from
May 27, 2024
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
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/django/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _simplify(self, pattern):
and isinstance(pattern.pattern, RoutePattern)
):
return self._new_style_group_matcher.sub(
lambda m: "{%s}" % m.group(2), pattern.pattern._route
lambda m: "{%s}" % m.group(2), str(pattern.pattern._route)
)

result = get_regex(pattern).pattern
Expand Down
12 changes: 12 additions & 0 deletions tests/integrations/django/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
import django
from django.utils.translation import pgettext_lazy


# django<2.0 has only `url` with regex based patterns.
Expand Down Expand Up @@ -116,3 +117,14 @@ def test_resolver_path_no_converter():
resolver = RavenResolver()
result = resolver.resolve("/api/v4/myproject", url_conf)
assert result == "/api/v4/{project_id}"


@pytest.mark.skipif(
django.VERSION < (2, 0),
reason="Django>=2.0 required for path patterns",
)
def test_resolver_path_with_i18n():
url_conf = (path(pgettext_lazy("url", "pgettext"), lambda x: ""),)
resolver = RavenResolver()
result = resolver.resolve("/pgettext", url_conf)
assert result == "/pgettext"
Loading