From 279d16f971e552cbcb6f2d6c673688c873246086 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Tue, 29 Oct 2024 06:49:26 -0400 Subject: [PATCH 1/3] In tests, error on deprecation warnings about python_multipart from starlette integrations --- tests/integrations/starlette/test_starlette.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/integrations/starlette/test_starlette.py b/tests/integrations/starlette/test_starlette.py index fd47895f5a..2d50fa4326 100644 --- a/tests/integrations/starlette/test_starlette.py +++ b/tests/integrations/starlette/test_starlette.py @@ -13,10 +13,16 @@ from sentry_sdk import capture_message, get_baggage, get_traceparent from sentry_sdk.integrations.asgi import SentryAsgiMiddleware -from sentry_sdk.integrations.starlette import ( - StarletteIntegration, - StarletteRequestExtractor, -) +with warnings.catch_warnings(): + # Error on deprecation-type warnings related to python_multipart, which are + # probably about migrating from "import multipart" to "import + # python_multipart". + for w in (PendingDeprecationWarning, DeprecationWarning): + warnings.filterwarnings("error", ".*python_multipart.*", category=w) + from sentry_sdk.integrations.starlette import ( + StarletteIntegration, + StarletteRequestExtractor, + ) from sentry_sdk.utils import parse_version import starlette From 56550e255d1e86fcfb15fec9eda1869ea66446c0 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Mon, 28 Oct 2024 12:56:23 -0400 Subject: [PATCH 2/3] Prefer python_multipart import over multipart See: https://github.com/Kludex/python-multipart/issues/16 See also releases 0.0.13 through 0.0.16 at https://github.com/Kludex/python-multipart/releases. --- sentry_sdk/integrations/starlette.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/starlette.py b/sentry_sdk/integrations/starlette.py index 52c64f6843..d9db8bd6b8 100644 --- a/sentry_sdk/integrations/starlette.py +++ b/sentry_sdk/integrations/starlette.py @@ -65,7 +65,12 @@ try: # Optional dependency of Starlette to parse form data. - import multipart # type: ignore + try: + # python-multipart 0.0.13 and later + import python_multipart as multipart # type: ignore + except ImportError: + # python-multipart 0.0.12 and earlier + import multipart # type: ignore except ImportError: multipart = None From 479c9512d4f288665e0a55b04978bc37de62537c Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Tue, 29 Oct 2024 13:00:20 +0100 Subject: [PATCH 3/3] remove testing code --- tests/integrations/starlette/test_starlette.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tests/integrations/starlette/test_starlette.py b/tests/integrations/starlette/test_starlette.py index 2d50fa4326..fd47895f5a 100644 --- a/tests/integrations/starlette/test_starlette.py +++ b/tests/integrations/starlette/test_starlette.py @@ -13,16 +13,10 @@ from sentry_sdk import capture_message, get_baggage, get_traceparent from sentry_sdk.integrations.asgi import SentryAsgiMiddleware -with warnings.catch_warnings(): - # Error on deprecation-type warnings related to python_multipart, which are - # probably about migrating from "import multipart" to "import - # python_multipart". - for w in (PendingDeprecationWarning, DeprecationWarning): - warnings.filterwarnings("error", ".*python_multipart.*", category=w) - from sentry_sdk.integrations.starlette import ( - StarletteIntegration, - StarletteRequestExtractor, - ) +from sentry_sdk.integrations.starlette import ( + StarletteIntegration, + StarletteRequestExtractor, +) from sentry_sdk.utils import parse_version import starlette