From b61e87396ef7781b193620b0638dcab127b328ad Mon Sep 17 00:00:00 2001 From: Emre K <110906681+kocaemre@users.noreply.github.com> Date: Tue, 13 Oct 2026 20:25:27 +0200 Subject: [PATCH] fix(conf): report legacy gRPC URLs as deprecations Signed-off-by: Emre K <110906681+kocaemre@users.noreply.github.com> --- dapr/conf/helpers.py | 6 +++++- tests/conf/helpers_test.py | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/dapr/conf/helpers.py b/dapr/conf/helpers.py index d2d187628..e8b9f5b03 100644 --- a/dapr/conf/helpers.py +++ b/dapr/conf/helpers.py @@ -40,8 +40,12 @@ def _set_scheme(self): if self._parsed_url.scheme in ['http', 'https']: self._scheme = URIParseConfig.DEFAULT_SCHEME + tls = str(self._parsed_url.scheme == 'https').lower() warn( - 'http and https schemes are deprecated for grpc, use myhost?tls=false or myhost?tls=true instead' + f'http and https schemes are deprecated for grpc, use ' + f'{self._hostname}:{self._parsed_url.port or URIParseConfig.DEFAULT_PORT}?tls={tls} instead', + DeprecationWarning, + stacklevel=3, ) return diff --git a/tests/conf/helpers_test.py b/tests/conf/helpers_test.py index d09eb3d9d..3bd8b4d72 100644 --- a/tests/conf/helpers_test.py +++ b/tests/conf/helpers_test.py @@ -1,9 +1,33 @@ import unittest +import warnings from dapr.conf.helpers import GrpcEndpoint class DaprClientHelpersTests(unittest.TestCase): + def test_http_scheme_deprecation_keeps_endpoint_and_points_to_caller(self): + for scheme, port, secure in [('http', 80, False), ('https', 443, True)]: + with self.subTest(scheme=scheme): + with self.assertWarns(DeprecationWarning) as warning: + endpoint = GrpcEndpoint(f'{scheme}://host:{port}') + self.assertIn('helpers_test.py', warning.filename) + self.assertIn(f'host:{port}?tls={str(secure).lower()}', str(warning.warning)) + self.assertEqual(endpoint.hostname, 'host') + self.assertEqual(endpoint.port_as_int, port) + self.assertEqual(endpoint.tls, secure) + self.assertEqual(endpoint.endpoint, f'dns:host:{port}') + + with self.assertRaises(ValueError): + GrpcEndpoint('https://host:443?tls=false') + + def test_http_scheme_emits_only_a_deprecation_warning(self): + for scheme, port in [('http', 80), ('https', 443)]: + with self.subTest(scheme=scheme): + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter('always') + GrpcEndpoint(f'{scheme}://host:{port}') + self.assertEqual([warning.category for warning in caught], [DeprecationWarning]) + def test_parse_grpc_endpoint(self): testcases = [ # Port only