: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(deletions): hide property removal from the deletion request admin form (#88128)
Paweł Szczur5cab210ade4b
diff --git a/posthog/admin/admins/data_deletion_request_admin.py b/posthog/admin/admins/data_deletion_request_admin.pyindex a69f577d3cf3..d0e4269eec73 100644--- a/posthog/admin/admins/data_deletion_request_admin.py+++ b/posthog/admin/admins/data_deletion_request_admin.py@@ -48,6 +48,8 @@ PERSON_REMOVAL_FIELDS = ("person_drop_recordings",)+UNSUPPORTED_REQUEST_TYPES = (RequestType.PERSON_REMOVAL, RequestType.PROPERTY_REMOVAL)+# Requests can only be edited while draft or pending. Once approved (or later), the# criteria are locked — operators must explicitly "revert to draft" to change them.EDITABLE_STATUSES = {RequestStatus.DRAFT, RequestStatus.PENDING}@@ -219,8 +221,11 @@ class DataDeletionRequestForm(forms.ModelForm):super().__init__(*args, **kwargs)request_type = self.fields.get("request_type")if isinstance(request_type, forms.ChoiceField):+ current_type = getattr(self.instance, "request_type", None)request_type.choices = [- (value, label) for value, label in RequestType.choices if value != RequestType.PERSON_REMOVAL+ (value, label)+ for value, label in RequestType.choices+ if value not in UNSUPPORTED_REQUEST_TYPES or value == current_type]diff --git a/posthog/admin/test_data_deletion_request_admin.py b/posthog/admin/test_data_deletion_request_admin.pyindex 4301efeaeae7..501bc399c530 100644--- a/posthog/admin/test_data_deletion_request_admin.py+++ b/posthog/admin/test_data_deletion_request_admin.py@@ -987,21 +987,29 @@ class TestDagsterRunLink(SimpleTestCase):self.assertEqual(admin_obj.last_dagster_run(DataDeletionRequest()), "—")-class TestDataDeletionRequestFormHidesPersonRemoval(SimpleTestCase):- def test_person_removal_hidden_from_type_picker_and_fields(self):+class TestDataDeletionRequestFormHidesUnsupportedTypes(SimpleTestCase):+ @staticmethod+ def _type_values(form) -> list[str]:from typing import castfrom django import forms- from posthog.admin.admins.data_deletion_request_admin import PERSON_REMOVAL_FIELDS, DataDeletionRequestForm-- form = DataDeletionRequestForm()request_type = form.fields["request_type"]assert isinstance(request_type, forms.ChoiceField)choices = cast("list[tuple[str, str]]", request_type.choices)- type_values = [value for value, _ in choices]- self.assertNotIn(RequestType.PERSON_REMOVAL, type_values)- self.assertIn(RequestType.EVENT_REMOVAL, type_values)- self.assertIn(RequestType.PROPERTY_REMOVAL, type_values)+ return [value for value, _ in choices]++ def test_only_event_removal_is_offered_on_a_new_request(self):+ from posthog.admin.admins.data_deletion_request_admin import PERSON_REMOVAL_FIELDS, DataDeletionRequestForm++ form = DataDeletionRequestForm()+ self.assertEqual(self._type_values(form), [RequestType.EVENT_REMOVAL])for field in PERSON_REMOVAL_FIELDS:self.assertNotIn(field, form.fields)++ @parameterized.expand([(RequestType.PROPERTY_REMOVAL,), (RequestType.PERSON_REMOVAL,)])+ def test_existing_request_keeps_its_own_type_selectable(self, request_type):+ from posthog.admin.admins.data_deletion_request_admin import DataDeletionRequestForm++ form = DataDeletionRequestForm(instance=DataDeletionRequest(team_id=1, request_type=request_type))+ self.assertIn(request_type, self._type_values(form))