Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .sampo/changesets/gentle-harbor-ilmatar.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 4 additions & 3 deletions posthog/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions posthog/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading