From 147bb352eced358c07c8e5167a23faa13c7cf976 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 17 Sep 2026 00:23:24 +0100 Subject: [PATCH] fix: report a Redis database number too long for int() to read The ASCII-digit check accepts any length, but since 3.11 Python refuses to convert a digit string past its conversion limit, so a long one raised ValueError straight through the CLI instead of the message every other unusable URL gets. --- docsgpt/deploy/commands.py | 10 +++++++++- tests/deploy/test_native.py | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docsgpt/deploy/commands.py b/docsgpt/deploy/commands.py index c03ccecb..19babb5a 100644 --- a/docsgpt/deploy/commands.py +++ b/docsgpt/deploy/commands.py @@ -227,7 +227,15 @@ def _redis_urls(base: str) -> dict[str, str]: f"the Redis URL {base!r} has {path!r} where a database number would go. Pass a URL like " "redis://host:6379 or redis://host:6379/5." ) - first = int(path) if path else 0 + try: + first = int(path) if path else 0 + except ValueError as exc: + # Python refuses to convert a digit string past its conversion limit, and that is a typo + # rather than a crash. + raise DeployError( + f"the Redis URL {base!r} has a database number too long to read. Pass a URL like " + "redis://host:6379 or redis://host:6379/5." + ) from exc return { key: urlunsplit((parts.scheme, parts.netloc, f"/{first + offset}", parts.query, parts.fragment)) for key, offset in (("CELERY_BROKER_URL", 0), ("CELERY_RESULT_BACKEND", 1), ("CACHE_REDIS_URL", 2)) diff --git a/tests/deploy/test_native.py b/tests/deploy/test_native.py index d5a41696..33a50568 100644 --- a/tests/deploy/test_native.py +++ b/tests/deploy/test_native.py @@ -224,6 +224,13 @@ class TestNativeUp: assert env["CELERY_BROKER_URL"] == "redis://[::1]:6379/2" assert env["CACHE_REDIS_URL"] == "redis://[::1]:6379/4" + def test_a_redis_database_number_too_long_to_convert_is_reported(self, tmp_path): + """Since 3.11 int() refuses a digit string past its limit, which the digit check let through.""" + argv = ["up", "--native", "--dir", str(tmp_path), "--yes", "--postgres-uri", "postgresql://localhost/d", + "--redis-url", "redis://localhost:6379/" + "1" * 5000] + with pytest.raises(DeployError, match="too long to read"): + _run(argv, _native_context()) + @pytest.mark.parametrize("url", ["localhost:6379", "redis+socket:///var/run/redis.sock", "redis://localhost:6379/queue"]) def test_a_redis_url_that_cannot_be_numbered_is_refused(self, tmp_path, url):