fix: refuse a Redis URL on port zero

parts.port returns 0 rather than raising, since 0 is inside the range it checks,
so the URL reached .env and the worker and cache had nothing to connect to.
This commit is contained in:
Alex committed 2026-09-17 00:44:19 +01:00
1 parent 51b2fa38de
commit 06f233925b
2 files changed
+9 -2

No files matched your search

+7 -1
View File
@@ -216,12 +216,18 @@ def _redis_urls(base: str) -> dict[str, str]:
# urlsplit raises on things like redis://[::1 ; that is a typo, not a crash.
raise DeployError(f"the Redis URL {base!r} could not be read: {exc}") from exc
try:
_ = parts.port # a non-numeric or out-of-range port raises here, not when the URL is split
port = parts.port # a non-numeric or out-of-range port raises here, not when the URL is split
except ValueError as exc:
raise DeployError(
f"the Redis URL {base!r} has an unusable port: {exc}. Pass a URL like "
"redis://host:6379 or redis://host:6379/5."
) from exc
if port == 0:
# urlsplit is happy with it, since 0 is inside the range, but nothing can connect to it.
raise DeployError(
f"the Redis URL {base!r} has an unusable port: 0. Pass a URL like "
"redis://host:6379 or redis://host:6379/5."
)
if parts.scheme not in ("redis", "rediss"):
raise DeployError(
f"the Redis URL {base!r} should start with redis:// or rediss://, with any options as "