Skip to content

Commit 44c6a60

Browse files
chore(test): avoid ValueErorr when @ not in netloc [backport #4914 to 1.6] (#4918)
Backport #4914 and #4915 Fix missing case where the `@` symbol is in the url but not in the netloc. Testing: This is tested in some framework tests (fastapi at least), that are failing at the moment, this should fix them - [ ] Followed the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines) when writing a release note. - [ ] Add additional sections for `feat` and `fix` pull requests. - [ ] [Library documentation](https://github.com/DataDog/dd-trace-py/tree/1.x/docs) and/or [Datadog's documentation site](https://github.com/DataDog/documentation/) is updated. Link to doc PR in description. - [ ] Title is accurate. - [ ] Description motivates each change. - [ ] No unnecessary changes were introduced in this PR. - [ ] Avoid breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Tests provided or description of manual testing performed is included in the code or PR. - [ ] Release note has been added and follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines), or else `changelog/no-changelog` label added. - [ ] All relevant GitHub issues are correctly linked. - [ ] Backports are identified and tagged with Mergifyio. Co-authored-by: Federico Mon <[email protected]>
1 parent fee6ddd commit 44c6a60

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

ddtrace/contrib/trace_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ def _sanitized_url(url):
289289
if "@" in url:
290290
parsed = parse.urlparse(url)
291291
netloc = parsed.netloc
292+
293+
if "@" not in netloc:
294+
# Safe url, `@` not in netloc
295+
return url
296+
292297
netloc = netloc[netloc.index("@") + 1 :]
293298
return parse.urlunparse(
294299
(
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
Fix for ValueError when ``@`` is not present in network location but other part of the url.

tests/tracer/test_trace_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ def test_ext_service(int_config, pin, config_val, default, expected):
339339
("GET", "http://user:pass@localhost/", 0, None, None, None, None, None, None, None),
340340
("GET", "http://user@localhost/", 0, None, None, None, None, None, None, None),
341341
("GET", "http://user:pass@localhost/api?q=test", 0, None, None, None, None, None, None, None),
342+
("GET", "http://localhost/api@test", 0, None, None, None, None, None, None, None),
343+
("GET", "http://localhost/?api@test", 0, None, None, None, None, None, None, None),
342344
],
343345
)
344346
def test_set_http_meta(

0 commit comments

Comments
 (0)