From 704ac1fe695cc1f9ab59520d34aaeadedd0077a2 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 24 Jun 2026 19:16:07 +0200 Subject: [PATCH] fix: clear feature flag called cache on shutdown --- .sampo/changesets/venerable-runesinger-vainamoinen.md | 5 +++++ posthog/client.py | 1 + posthog/test/test_client.py | 8 ++++++++ 3 files changed, 14 insertions(+) create mode 100644 .sampo/changesets/venerable-runesinger-vainamoinen.md diff --git a/.sampo/changesets/venerable-runesinger-vainamoinen.md b/.sampo/changesets/venerable-runesinger-vainamoinen.md new file mode 100644 index 00000000..a8a96058 --- /dev/null +++ b/.sampo/changesets/venerable-runesinger-vainamoinen.md @@ -0,0 +1,5 @@ +--- +pypi/posthog: patch +--- + +Clear feature flag called cache on shutdown diff --git a/posthog/client.py b/posthog/client.py index 0ae99bc2..1fbff223 100644 --- a/posthog/client.py +++ b/posthog/client.py @@ -1716,6 +1716,7 @@ def shutdown(self) -> None: """ self.flush(timeout_seconds=None) self.join() + self.distinct_ids_feature_flags_reported.clear() if self.exception_capture: self.exception_capture.close() diff --git a/posthog/test/test_client.py b/posthog/test/test_client.py index c81f3b92..10a173fa 100644 --- a/posthog/test/test_client.py +++ b/posthog/test/test_client.py @@ -2026,6 +2026,14 @@ def test_shutdown(self): for consumer in client.consumers: self.assertFalse(consumer.is_alive()) + def test_shutdown_clears_feature_flag_called_dedupe_cache(self): + client = Client(FAKE_TEST_API_KEY, send=False, thread=0) + client.distinct_ids_feature_flags_reported["user"] = {("flag", True, ())} + + client.shutdown() + + self.assertEqual(len(client.distinct_ids_feature_flags_reported), 0) + def test_shutdown_flushes_without_timeout(self): client = Client(FAKE_TEST_API_KEY, send=False, thread=0)