Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(experiments): reflect disabled flag in archive response (#70463)

Andersd1180479dd44
diff --git a/products/experiments/backend/experiment_service.py b/products/experiments/backend/experiment_service.py
index d571bb5aec54..ebdc91aed4c9 100644
--- a/products/experiments/backend/experiment_service.py
+++ b/products/experiments/backend/experiment_service.py
@@ -1674,6 +1674,10 @@ class ExperimentService:
feature_flag.archived = True
feature_flag.save(update_fields=["archived", "active"])
+ # Sync the cached relation so the serialized response reflects the flag we just
+ # mutated — experiment.feature_flag is a separately-loaded instance otherwise.
+ experiment.feature_flag = feature_flag
+
# Remember that this experiment archived the flag, so unarchiving the experiment
# only undoes its own archive — never one the user performed manually.
experiment.feature_flag_auto_archived = True
diff --git a/products/experiments/backend/test/test_presentation_api.py b/products/experiments/backend/test/test_presentation_api.py
index 3489b19e1f93..32bf80605425 100644
--- a/products/experiments/backend/test/test_presentation_api.py
+++ b/products/experiments/backend/test/test_presentation_api.py
@@ -5181,6 +5181,10 @@ class TestExperimentCRUD(_HoistFlagConfigClientMixin, APILicensedTest):
)
self.assertEqual(archive_response.status_code, status.HTTP_200_OK)
+ # The response must reflect the flag we just disabled, not a stale pre-mutation echo.
+ # MinimalFeatureFlagSerializer exposes active but not archived, so archived is checked on the row.
+ self.assertFalse(archive_response.json()["feature_flag"]["active"])
+
feature_flag = FeatureFlag.objects.get(id=feature_flag_id)
self.assertFalse(feature_flag.active)
self.assertTrue(feature_flag.archived)