From 8765cd9df950196e2e8683d91d37e85e05289d5c Mon Sep 17 00:00:00 2001 From: Yun Kim <35776586+Yun-Kim@users.noreply.github.com> Date: Mon, 21 Nov 2022 08:24:19 -0500 Subject: [PATCH] fix(httpx): manually construct removed `URL.raw` property (#4595) ## Description [As of `httpx==0.23.1`](https://github.com/encode/httpx/pull/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 6a1948d775643ef7fdceff0f056212d0f4355dd3) --- ddtrace/contrib/httpx/patch.py | 11 ++++++++++- riotfile.py | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ddtrace/contrib/httpx/patch.py b/ddtrace/contrib/httpx/patch.py index 35379ddd598..bbeace21220 100644 --- a/ddtrace/contrib/httpx/patch.py +++ b/ddtrace/contrib/httpx/patch.py @@ -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", { @@ -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)) diff --git a/riotfile.py b/riotfile.py index 39e38fe5150..34c970b2585 100644 --- a/riotfile.py +++ b/riotfile.py @@ -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, ], },