From a03eccd3012fe43177e0024fb3b0656a9820a960 Mon Sep 17 00:00:00 2001 From: Ioannis J Date: Wed, 11 Nov 2026 14:32:04 +0200 Subject: [PATCH] fix(flags): keep IPv6 brackets in Redis fallback cache URLs --- .sampo/changesets/gentle-harbor-ilmatar.md | 5 +++++ posthog/client.py | 7 ++++--- posthog/test/test_client.py | 9 +++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 .sampo/changesets/gentle-harbor-ilmatar.md diff --git a/.sampo/changesets/gentle-harbor-ilmatar.md b/.sampo/changesets/gentle-harbor-ilmatar.md new file mode 100644 index 000000000..4c9ee83ec --- /dev/null +++ b/.sampo/changesets/gentle-harbor-ilmatar.md @@ -0,0 +1,5 @@ +--- +pypi/posthog: patch +--- + +Fix `flag_fallback_cache_url` for Redis URLs with an IPv6 host: the brackets are kept, so the Redis flag cache is no longer disabled. diff --git a/posthog/client.py b/posthog/client.py index 5c075da73..35380d979 100644 --- a/posthog/client.py +++ b/posthog/client.py @@ -5679,9 +5679,10 @@ def _initialize_flag_cache(self, cache_url): redis_url = f"{parsed.scheme}://" if parsed.username or parsed.password: redis_url += f"{parsed.username or ''}:{parsed.password or ''}@" - redis_url += ( - f"{parsed.hostname or 'localhost'}:{parsed.port or 6379}" - ) + host = parsed.hostname or "localhost" + if ":" in host: + host = f"[{host}]" + redis_url += f"{host}:{parsed.port or 6379}" if parsed.path: redis_url += parsed.path diff --git a/posthog/test/test_client.py b/posthog/test/test_client.py index 2a1923028..aee8342ab 100644 --- a/posthog/test/test_client.py +++ b/posthog/test/test_client.py @@ -2597,6 +2597,15 @@ def test_shutdown_clears_feature_flag_called_dedupe_cache(self): "rediss://user:secret@cache.example.com:6380/1?ttl=120", "rediss://user:secret@cache.example.com:6380/1", ), + ("redis://[::1]:6379/0?ttl=120", "redis://[::1]:6379/0"), + ( + "rediss://[2001:db8::1]:6380/1?ttl=120", + "rediss://[2001:db8::1]:6380/1", + ), + ( + "redis://user:p%40ss@[::1]:6379/0?ttl=120", + "redis://user:p%40ss@[::1]:6379/0", + ), ] ) def test_flag_fallback_cache_url_accepts_redis_schemes(