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(data-deletion): use deployed json drop keys udf (#111927)

Paweł Szczur159d8ca8eed6
diff --git a/posthog/dags/data_deletion_requests.py b/posthog/dags/data_deletion_requests.py
index 27e9f25c39da..7c16d1b4cf0e 100644
--- a/posthog/dags/data_deletion_requests.py
+++ b/posthog/dags/data_deletion_requests.py
@@ -1131,11 +1131,11 @@ def _cleaned_select_list(
# let the cast below turn the cleaned string back into the JSON column type.
if deletion_request.properties:
source = "toJSONString(properties)" if target.json_schema else "properties"
- replacements["properties"] = f"JSONDropKeys(%(keys)s)({source})"
+ replacements["properties"] = f"JSONDropKeysPool({source}, %(keys)s)"
params["keys"] = deletion_request.properties
if deletion_request.person_properties:
source = "toJSONString(person_properties)" if target.json_schema else "person_properties"
- replacements["person_properties"] = f"JSONDropKeys(%(person_keys)s)({source})"
+ replacements["person_properties"] = f"JSONDropKeysPool({source}, %(person_keys)s)"
params["person_keys"] = deletion_request.person_properties
for name, is_nullable in mat_cols:
replacements[name] = "NULL" if is_nullable else "''"
diff --git a/posthog/dags/tests/test_data_deletion_requests.py b/posthog/dags/tests/test_data_deletion_requests.py
index 1172e1b5acd0..9d88e65b5e9c 100644
--- a/posthog/dags/tests/test_data_deletion_requests.py
+++ b/posthog/dags/tests/test_data_deletion_requests.py
@@ -30,6 +30,7 @@ from posthog.dags.data_deletion_requests import (
HogQLEventRemovalContext,
PersonRemovalContext,
PropertyRemovalTarget,
+ _cleaned_select_list,
_property_removal_where,
_refuse_property_removal_unsweepable,
_ShardStaging,
@@ -1029,6 +1030,39 @@ def test_auto_approve_schedule_launches_a_run_on_tick():
PROP_TEAM_ID = 88888
+def test_property_removal_cleaning_uses_unversioned_pool_udf() -> None:
+ client = Mock(spec=Client)
+ client.execute.return_value = [
+ ("properties", "String"),
+ ("person_properties", "String"),
+ ("inserted_at", "Nullable(DateTime64(6, 'UTC'))"),
+ ("_timestamp", "DateTime"),
+ ]
+ request = DeletionRequestContext(
+ request_id=str(uuid4()),
+ team_id=PROP_TEAM_ID,
+ start_time=datetime.now() - timedelta(days=1),
+ end_time=datetime.now(),
+ events=["$pageview"],
+ properties=["$ip"],
+ person_properties=["email"],
+ )
+
+ cleaned = _cleaned_select_list(
+ client,
+ request,
+ PropertyRemovalTarget(table="sharded_events", shard=1, json_schema=False),
+ [],
+ "2026-10-05 13:03:36.419459",
+ )
+
+ assert "CAST(JSONDropKeysPool(properties, %(keys)s) AS String) AS `properties`" in cleaned.expressions
+ assert (
+ "CAST(JSONDropKeysPool(person_properties, %(person_keys)s) AS String) AS `person_properties`"
+ in cleaned.expressions
+ )
+
+
def _insert_events_with_properties(events: list[tuple], client: Client) -> None:
"""Insert events with (team_id, event, uuid, timestamp, properties_json)."""
client.execute(