From 5b45a140b93c27b10302b2c3577fdcfd81b3a8b3 Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Sat, 3 Dec 2022 18:30:21 -0800 Subject: [PATCH] Fixes issue when the Redis URL also specifies a port --- src/paperless/settings.py | 5 +++-- src/paperless/tests/test_settings.py | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/paperless/settings.py b/src/paperless/settings.py index 3271ae7e6..c11e43489 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -78,11 +78,11 @@ def _parse_redis_url(env_redis: Optional[str]) -> Tuple[str]: if env_redis is None: return ("redis://localhost:6379", "redis://localhost:6379") - _, path = env_redis.split(":") - if "unix" in env_redis.lower(): # channels_redis socket format, looks like: # "unix:///path/to/redis.sock" + _, path = env_redis.split(":") + # Optionally setting a db number if "?db=" in env_redis: path, number = path.split("?db=") return (f"redis+socket:{path}?virtual_host={number}", env_redis) @@ -92,6 +92,7 @@ def _parse_redis_url(env_redis: Optional[str]) -> Tuple[str]: elif "+socket" in env_redis.lower(): # celery socket style, looks like: # "redis+socket:///path/to/redis.sock" + _, path = env_redis.split(":") if "?virtual_host=" in env_redis: # Virtual host (aka db number) path, number = path.split("?virtual_host=") diff --git a/src/paperless/tests/test_settings.py b/src/paperless/tests/test_settings.py index 346f2d098..71926542d 100644 --- a/src/paperless/tests/test_settings.py +++ b/src/paperless/tests/test_settings.py @@ -131,6 +131,11 @@ class TestIgnoreDateParsing(TestCase): "unix:///run/redis/redis.sock?db=10", ), ), + # Just a host with a port + ( + "redis://myredishost:6379", + ("redis://myredishost:6379", "redis://myredishost:6379"), + ), ]: result = _parse_redis_url(input) self.assertTupleEqual(expected, result)