Skip to content

Commit

Permalink
fix(httpx): manually construct removed URL.raw property (#4595)
Browse files Browse the repository at this point in the history
## Description
[As of `httpx==0.23.1`](encode/httpx#2241), the `URL.raw` property was removed, which broke our `_url_to_str()` helper that uses that property to construct the raw URL.

However, the removed property was simply a combination of already existing (and still existing) properties in the `URL` object, which we can use to manually consturct the raw URL. I've version gated it such that nothing's changed for previous versions of `httpx`, but moving forward we'll manually construct the raw URL.

## Checklist
- [x] Add additional sections for `feat` and `fix` pull requests.
- [x] [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.

## Motivation

## Design

## Testing strategy

## Relevant issue(s)

## Testing strategy

## Reviewer Checklist
- [ ] 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 for fixes and features, or else `changelog/no-changelog` label added.
- [ ] All relevant GitHub issues are correctly linked.
- [ ] Backports are identified and tagged with Mergifyio.

(cherry picked from commit 6a1948d)
  • Loading branch information
Yun-Kim authored and mergify[bot] committed Nov 21, 2022
1 parent 6d3183d commit 8765cd9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion ddtrace/contrib/httpx/patch.py
Expand Up @@ -24,6 +24,8 @@
from ddtrace import Span
from ddtrace.vendor.wrapt import BoundFunctionWrapper

HTTPX_VERSION = tuple(map(int, httpx.__version__.split(".")))

config._add(
"httpx",
{
Expand All @@ -39,7 +41,14 @@ def _url_to_str(url):
"""
Helper to convert the httpx.URL parts from bytes to a str
"""
scheme, host, port, raw_path = url.raw
# httpx==0.23.1 removed URL.raw, must construct it manually
if HTTPX_VERSION >= (0, 23, 1):
scheme = url.raw_scheme
host = url.raw_host
port = url.port
raw_path = url.raw_path
else:
scheme, host, port, raw_path = url.raw
url = scheme + b"://" + host
if port is not None:
url += b":" + ensure_binary(str(port))
Expand Down
2 changes: 1 addition & 1 deletion riotfile.py
Expand Up @@ -1716,7 +1716,7 @@ def select_pys(min_version=MIN_PYTHON_VERSION, max_version=MAX_PYTHON_VERSION):
"~=0.16.0",
"~=0.17.0",
"~=0.18.0",
"<1.0.0",
"~=0.22.0",
latest,
],
},
Expand Down

0 comments on commit 8765cd9

Please sign in to comment.