Skip to content

Commit b496a71

Browse files
authored
fix(django): Proper transaction names for i18n routes (#3104)
`pattern.pattern._route` for i18n'd Django routes is a proxy object rather than a string. This causes an exception in the resolver, leading to the transaction not getting a proper name but rather falling back to the default `Generic WSGI request`. The string representation of the proxy object is the actual desired endpoint route, so let's use that.
1 parent 651f84d commit b496a71

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

sentry_sdk/integrations/django/transactions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def _simplify(self, pattern):
7474
and isinstance(pattern.pattern, RoutePattern)
7575
):
7676
return self._new_style_group_matcher.sub(
77-
lambda m: "{%s}" % m.group(2), pattern.pattern._route
77+
lambda m: "{%s}" % m.group(2), str(pattern.pattern._route)
7878
)
7979

8080
result = get_regex(pattern).pattern

tests/integrations/django/test_transactions.py

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44
import django
5+
from django.utils.translation import pgettext_lazy
56

67

78
# django<2.0 has only `url` with regex based patterns.
@@ -116,3 +117,14 @@ def test_resolver_path_no_converter():
116117
resolver = RavenResolver()
117118
result = resolver.resolve("/api/v4/myproject", url_conf)
118119
assert result == "/api/v4/{project_id}"
120+
121+
122+
@pytest.mark.skipif(
123+
django.VERSION < (2, 0),
124+
reason="Django>=2.0 required for path patterns",
125+
)
126+
def test_resolver_path_with_i18n():
127+
url_conf = (path(pgettext_lazy("url", "pgettext"), lambda x: ""),)
128+
resolver = RavenResolver()
129+
result = resolver.resolve("/pgettext", url_conf)
130+
assert result == "/pgettext"

0 commit comments

Comments
 (0)