mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-06 04:14:19 +00:00
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.
This commit is contained in:
1 parent
0d153d3c0d
commit
147bb352ec
2 files changed
+16
-1
No files matched your search
@@ -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))
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user