: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
feat(logs): create extractIPv4Substrings UDF via migration (#93150)
Frank Hamandc340744bb51a
diff --git a/posthog/clickhouse/logs/functions.py b/posthog/clickhouse/logs/functions.pynew file mode 100644index 000000000000..9fdc60550fce--- /dev/null+++ b/posthog/clickhouse/logs/functions.py@@ -0,0 +1,10 @@+FUNCTION_NAME = "extractIPv4Substrings"+++def EXTRACT_IPV4_SUBSTRINGS_FUNCTION_SQL():+ return rf"""+CREATE OR REPLACE FUNCTION {FUNCTION_NAME} AS+(+ body -> extractAll(body, '(\d\.((25[0-5]|(2[0-4]|1{{0,1}}[0-9]){{0,1}}[0-9])\.){{2,2}}([0-9]))')+)+"""diff --git a/posthog/clickhouse/migrations/0317_extract_ipv4_substrings_function.py b/posthog/clickhouse/migrations/0317_extract_ipv4_substrings_function.pynew file mode 100644index 000000000000..876481ede521--- /dev/null+++ b/posthog/clickhouse/migrations/0317_extract_ipv4_substrings_function.py@@ -0,0 +1,7 @@+from posthog.clickhouse.client.connection import NodeRole+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions+from posthog.clickhouse.logs.functions import EXTRACT_IPV4_SUBSTRINGS_FUNCTION_SQL++operations = [+ run_sql_with_exceptions(EXTRACT_IPV4_SUBSTRINGS_FUNCTION_SQL(), node_roles=[NodeRole.LOGS]),+]diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txtindex 561cee7b9c11..404e381e3091 100644--- a/posthog/clickhouse/migrations/max_migration.txt+++ b/posthog/clickhouse/migrations/max_migration.txt@@ -1 +1 @@-0316_metrics2_drop_uuid_and_minute_projection+0317_extract_ipv4_substrings_functiondiff --git a/products/access_control/backend/presentation/access_control.py b/products/access_control/backend/presentation/access_control.pyindex 930c8cbe08ac..5bcb57eda980 100644--- a/products/access_control/backend/presentation/access_control.py+++ b/products/access_control/backend/presentation/access_control.py@@ -495,6 +495,15 @@ class AccessControlViewSetMixin(_GenericViewSet):if is_resource_level and resource != "project":raise exceptions.ValidationError("Resource-level access controls can only be configured for projects.")+ # A resource-level rule carries no resource_id, so a body that names one asks to write an+ # object rule through the project's endpoint. The serializer's identity check compares+ # primary keys only, and an object's pk can equal the project's, so it lets such a body+ # through whenever the two numbers happen to match.+ if is_resource_level and request.data.get("resource_id"):+ raise exceptions.PermissionDenied(+ "Cannot modify access controls for a resource different from the URL target."+ )+obj = self.get_object()resource_id = str(obj.id)team = cast(Team, self.team) # type: ignore