summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Manganiello <adamantike@users.noreply.github.com>2022-02-02 10:23:14 -0300
committerGitHub <noreply@github.com>2022-02-02 19:23:14 +0600
commit2f3b153acce0ab826ed23caffd9a293978cfc168 (patch)
tree1c132c3ebbb9eadea0c499ffe85619f0247295b2
parentac92e047c10bcb246589a2c3c23626ad720008e8 (diff)
downloadkombu-2f3b153acce0ab826ed23caffd9a293978cfc168.tar.gz
Warn about missing hostname only when default one is available (#1488)
* Warn about missing hostname only when default one is available The `No hostname was supplied` warning is affecting projects that use AWS SQS (as detailed in #1357), as a hostname is not required when setting up the broker URL. Instead, the official documentation [0] specifies that the valid broker URL formats are: * `sqs://` * `sqs://aws_access_key_id:aws_secret_access_key@` With these formats, the `kombu.utils.url.parse_url` util doesn't return a hostname, and workers end up triggering the following warning: > No hostname was supplied. Reverting to default 'None' As the SQS transport doesn't provide a default value for hostname, this diff changes the behavior to only warn the user when the hostname hasn't been supplied but a default one is being set by the default connection parameters for the defined transport. Fixes #1357. [0] https://docs.celeryproject.org/en/stable/getting-started/backends-and-brokers/sqs.html#configuration * Use caplog default logging level of WARNING
-rw-r--r--kombu/connection.py2
-rw-r--r--t/unit/test_connection.py13
2 files changed, 14 insertions, 1 deletions
diff --git a/kombu/connection.py b/kombu/connection.py
index 03b3161d..e2dd69b6 100644
--- a/kombu/connection.py
+++ b/kombu/connection.py
@@ -625,7 +625,7 @@ class Connection:
transport_cls, transport_cls)
D = self.transport.default_connection_params
- if not self.hostname:
+ if not self.hostname and D.get('hostname'):
logger.warning(
"No hostname was supplied. "
f"Reverting to default '{D.get('hostname')}'")
diff --git a/t/unit/test_connection.py b/t/unit/test_connection.py
index b65416e8..17ea7b34 100644
--- a/t/unit/test_connection.py
+++ b/t/unit/test_connection.py
@@ -99,6 +99,19 @@ class test_connection_utils:
# see Appendix A of http://www.rabbitmq.com/uri-spec.html
self.assert_info(Connection(url), **expected)
+ @pytest.mark.parametrize('url,expected', [
+ ('sqs://user:pass@',
+ {'userid': None, 'password': None, 'hostname': None,
+ 'port': None, 'virtual_host': '/'}),
+ ('sqs://',
+ {'userid': None, 'password': None, 'hostname': None,
+ 'port': None, 'virtual_host': '/'}),
+ ])
+ def test_sqs_example_urls(self, url, expected, caplog):
+ pytest.importorskip('boto3')
+ self.assert_info(Connection('sqs://'), **expected)
+ assert not caplog.records
+
@pytest.mark.skip('TODO: urllib cannot parse ipv6 urls')
def test_url_IPV6(self):
self.assert_info(