: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
chore(workflows): seal the product and turn on the contract-check skip (#113774)
Harley Alexander988c63675fab
diff --git a/products/isolation_baseline.txt b/products/isolation_baseline.txtindex 15cb7ed9ed43..bce2298a8e57 100644--- a/products/isolation_baseline.txt+++ b/products/isolation_baseline.txt@@ -75,4 +75,3 @@ tracinguser_interviewswarehouse_sources_queueweb_analytics-workflowsdiff --git a/products/messaging/backend/api/message_templates.py b/products/messaging/backend/api/message_templates.pyindex f950a0080120..30721cdea784 100644--- a/products/messaging/backend/api/message_templates.py+++ b/products/messaging/backend/api/message_templates.py@@ -1,7 +1,7 @@from copy import deepcopyfrom typing import Any-from django.db import models, transaction+from django.db import transactionimport structlogfrom drf_spectacular.utils import extend_schema, extend_schema_field@@ -22,6 +22,7 @@ from products.messaging.backend.api.design_operations import apply_design_operatfrom products.messaging.backend.api.design_validation import validate_designfrom products.messaging.backend.models.message_category import MessageCategoryfrom products.messaging.backend.models.message_template import MessageTemplate+from products.messaging.backend.presentation.serializers import DesignOperationSerializerfrom products.messaging.backend.unlayer import UnlayerNotConfiguredError, UnlayerRenderError, render_design_htmlfrom products.notifications.backend.facade.api import publish_resource_edited@@ -180,96 +181,6 @@ class MessageTemplateSerializer(serializers.ModelSerializer):return instance-class EmailTemplateDesignOperation(models.TextChoices):- UPDATE_CONTENT = "update_content", "update_content"- UPDATE_COLUMN = "update_column", "update_column"- UPDATE_ROW = "update_row", "update_row"- UPDATE_BODY = "update_body", "update_body"- ADD_CONTENT = "add_content", "add_content"- REMOVE_CONTENT = "remove_content", "remove_content"- MOVE_CONTENT = "move_content", "move_content"- ADD_ROW = "add_row", "add_row"- REMOVE_ROW = "remove_row", "remove_row"---DESIGN_OPERATION_TYPES = list(EmailTemplateDesignOperation.values)--# Per-op required fields, validated in DesignOperationSerializer.validate so a malformed op is rejected-# before any are applied (the whole batch is atomic).-_DESIGN_OPERATION_REQUIRED_FIELDS: dict[str, list[str]] = {- "update_content": ["id", "patch"],- "update_column": ["id", "patch"],- "update_row": ["id", "patch"],- "update_body": ["patch"],- "add_content": ["column_id", "content"],- "remove_content": ["id"],- "move_content": ["id", "column_id"],- "add_row": ["row"],- "remove_row": ["id"],-}---class DesignOperationSerializer(serializers.Serializer):- op = serializers.ChoiceField(- choices=DESIGN_OPERATION_TYPES,- help_text=(- "Design edit. update_content {id, patch}: deep-merge patch into the content block's fields (a null "- "leaf deletes that key) — the surgical path, e.g. change just values.text. update_row / update_column "- "{id, patch} and update_body {patch}: same deep-merge for row/column/body-level settings. add_content "- "{column_id, content, index?}: insert a content block into a column (id and Unlayer numbering are "- "filled in for you). remove_content {id} / move_content {id, column_id, index?}: delete or relocate a "- "block. add_row {row, index?} / remove_row {id}: add or delete a row."- ),- )- id = serializers.CharField(- required=False,- help_text="Target node id. Required for update_content/column/row, remove_content, remove_row, move_content.",- )- column_id = serializers.CharField(- required=False, help_text="Target column id. Required for add_content and move_content."- )- patch = serializers.JSONField(- required=False,- help_text=(- "update_* only. Partial fields deep-merged into the existing node; a null leaf deletes that key. "- "e.g. {values: {text: '<p>Hi</p>'}} changes only the block's text."- ),- )- content = serializers.JSONField(- required=False,- help_text=(- "add_content only. A content block {type, values: {...}}; omit id and values._meta — they're assigned "- "server-side. type is one of text, heading, button, image, divider, html, etc."- ),- )- row = serializers.JSONField(- required=False,- help_text=(- "add_row only. A full row {cells, columns: [{contents: [...], values}], values}; ids and Unlayer "- "numbering are assigned server-side for the row and everything nested in it."- ),- )- index = serializers.IntegerField(- required=False,- help_text="add_*/move_content only. 0-based insert position; omit to append to the end.",- )-- def validate(self, data: Any) -> Any:- op = data["op"]- missing = [field for field in _DESIGN_OPERATION_REQUIRED_FIELDS[op] if data.get(field) is None]- if missing:- raise serializers.ValidationError(f"op '{op}' requires: {', '.join(missing)}")- if op in ("update_content", "update_column", "update_row", "update_body") and not isinstance(- data.get("patch"), dict- ):- raise serializers.ValidationError(f"{op} 'patch' must be an object")- if op == "add_content" and not isinstance(data.get("content"), dict):- raise serializers.ValidationError("add_content 'content' must be an object")- if op == "add_row" and not isinstance(data.get("row"), dict):- raise serializers.ValidationError("add_row 'row' must be an object")- return data--class DesignPatchSerializer(serializers.Serializer):operations = serializers.ListField(child=DesignOperationSerializer(),diff --git a/products/messaging/backend/presentation/__init__.py b/products/messaging/backend/presentation/__init__.pynew file mode 100644index 000000000000..e69de29bb2d1diff --git a/products/messaging/backend/presentation/serializers.py b/products/messaging/backend/presentation/serializers.pynew file mode 100644index 000000000000..7428b6eaa692--- /dev/null+++ b/products/messaging/backend/presentation/serializers.py@@ -0,0 +1,95 @@+from typing import Any++from django.db import models++from rest_framework import serializers+++class EmailTemplateDesignOperation(models.TextChoices):+ UPDATE_CONTENT = "update_content", "update_content"+ UPDATE_COLUMN = "update_column", "update_column"+ UPDATE_ROW = "update_row", "update_row"+ UPDATE_BODY = "update_body", "update_body"+ ADD_CONTENT = "add_content", "add_content"+ REMOVE_CONTENT = "remove_content", "remove_content"+ MOVE_CONTENT = "move_content", "move_content"+ ADD_ROW = "add_row", "add_row"+ REMOVE_ROW = "remove_row", "remove_row"+++DESIGN_OPERATION_TYPES = list(EmailTemplateDesignOperation.values)++# Per-op required fields, validated in DesignOperationSerializer.validate so a malformed op is rejected+# before any are applied (the whole batch is atomic).+_DESIGN_OPERATION_REQUIRED_FIELDS: dict[str, list[str]] = {+ "update_content": ["id", "patch"],+ "update_column": ["id", "patch"],+ "update_row": ["id", "patch"],+ "update_body": ["patch"],+ "add_content": ["column_id", "content"],+ "remove_content": ["id"],+ "move_content": ["id", "column_id"],+ "add_row": ["row"],+ "remove_row": ["id"],+}+++class DesignOperationSerializer(serializers.Serializer):+ op = serializers.ChoiceField(+ choices=DESIGN_OPERATION_TYPES,+ help_text=(+ "Design edit. update_content {id, patch}: deep-merge patch into the content block's fields (a null "+ "leaf deletes that key) — the surgical path, e.g. change just values.text. update_row / update_column "+ "{id, patch} and update_body {patch}: same deep-merge for row/column/body-level settings. add_content "+ "{column_id, content, index?}: insert a content block into a column (id and Unlayer numbering are "+ "filled in for you). remove_content {id} / move_content {id, column_id, index?}: delete or relocate a "+ "block. add_row {row, index?} / remove_row {id}: add or delete a row."+ ),+ )+ id = serializers.CharField(+ required=False,+ help_text="Target node id. Required for update_content/column/row, remove_content, remove_row, move_content.",+ )+ column_id = serializers.CharField(+ required=False, help_text="Target column id. Required for add_content and move_content."+ )+ patch = serializers.JSONField(+ required=False,+ help_text=(+ "update_* only. Partial fields deep-merged into the existing node; a null leaf deletes that key. "+ "e.g. {values: {text: '<p>Hi</p>'}} changes only the block's text."+ ),+ )+ content = serializers.JSONField(+ required=False,+ help_text=(+ "add_content only. A content block {type, values: {...}}; omit id and values._meta — they're assigned "+ "server-side. type is one of text, heading, button, image, divider, html, etc."+ ),+ )+ row = serializers.JSONField(+ required=False,+ help_text=(+ "add_row only. A full row {cells, columns: [{contents: [...], values}], values}; ids and Unlayer "+ "numbering are assigned server-side for the row and everything nested in it."+ ),+ )+ index = serializers.IntegerField(+ required=False,+ help_text="add_*/move_content only. 0-based insert position; omit to append to the end.",+ )++ def validate(self, data: Any) -> Any:+ op = data["op"]+ missing = [field for field in _DESIGN_OPERATION_REQUIRED_FIELDS[op] if data.get(field) is None]+ if missing:+ raise serializers.ValidationError(f"op '{op}' requires: {', '.join(missing)}")+ if op in ("update_content", "update_column", "update_row", "update_body") and not isinstance(+ data.get("patch"), dict+ ):+ raise serializers.ValidationError(f"{op} 'patch' must be an object")+ if op == "add_content" and not isinstance(data.get("content"), dict):+ raise serializers.ValidationError("add_content 'content' must be an object")+ if op == "add_row" and not isinstance(data.get("row"), dict):+ raise serializers.ValidationError("add_row 'row' must be an object")+ return datadiff --git a/products/workflows/backend/facade/contracts.py b/products/workflows/backend/facade/contracts.pyindex 0ae3917fde33..1551940ae2d0 100644--- a/products/workflows/backend/facade/contracts.py+++ b/products/workflows/backend/facade/contracts.py@@ -283,6 +283,10 @@ class WorkflowTemplate:variables: list[dict[str, Any]] | None+class WorkflowTemplateNotFound(Exception):+ pass++@frozenclass FunctionTemplateSchema:"""The parts of a cdp function template that a workflow step validates its inputs against."""diff --git a/products/workflows/backend/facade/templates.py b/products/workflows/backend/facade/templates.pyindex d5333a1ac112..51f0a7463b63 100644--- a/products/workflows/backend/facade/templates.py+++ b/products/workflows/backend/facade/templates.py@@ -2,7 +2,6 @@templates that ship as code."""from products.workflows.backend.services.hog_flow_templates import (- WorkflowTemplateNotFound,create_template,delete_template,function_template_exists,@@ -15,7 +14,6 @@ from products.workflows.backend.services.hog_flow_templates import ()__all__ = [- "WorkflowTemplateNotFound","create_template","delete_template","function_template_exists",diff --git a/products/workflows/backend/presentation/views/hog_flow.py b/products/workflows/backend/presentation/views/hog_flow.pyindex a4f2d826a53f..ed73dc79160d 100644--- a/products/workflows/backend/presentation/views/hog_flow.py+++ b/products/workflows/backend/presentation/views/hog_flow.py@@ -97,7 +97,7 @@ from products.access_control.backend.presentation.access_control import (AccessControlViewSetMixin,UserAccessControlSerializerMixin,)-from products.messaging.backend.api.message_templates import DesignOperationSerializer+from products.messaging.backend.presentation.serializers import DesignOperationSerializerfrom products.notifications.backend.facade.api import publish_resource_editedfrom products.tasks.backend.facade.api import list_workflow_last_runsfrom products.tasks.backend.facade.contracts import WorkflowLastRunDTOdiff --git a/products/workflows/backend/presentation/views/hog_flow_template.py b/products/workflows/backend/presentation/views/hog_flow_template.pyindex 0fd62e1c44fa..7b396ef9c8df 100644--- a/products/workflows/backend/presentation/views/hog_flow_template.py+++ b/products/workflows/backend/presentation/views/hog_flow_template.py@@ -17,10 +17,9 @@ from posthog.helpers.impersonation import is_impersonatedfrom posthog.models import Userfrom posthog.models.activity_logging.activity_log import Detail, log_activity-from products.workflows.backend.facade.contracts import WorkflowTemplate+from products.workflows.backend.facade.contracts import WorkflowTemplate, WorkflowTemplateNotFoundfrom products.workflows.backend.facade.enums import HogFlowTemplateExitCondition, HogFlowTemplateScopefrom products.workflows.backend.facade.templates import (- WorkflowTemplateNotFound,create_template,delete_template,function_template_exists,diff --git a/products/workflows/backend/services/hog_flow_templates.py b/products/workflows/backend/services/hog_flow_templates.pyindex 1a185fd56aa1..3bf6f2899baa 100644--- a/products/workflows/backend/services/hog_flow_templates.py+++ b/products/workflows/backend/services/hog_flow_templates.py@@ -5,7 +5,11 @@ from uuid import UUIDfrom django.db.models import Q, QuerySetfrom products.cdp.backend.models.hog_function_template import HogFunctionTemplate-from products.workflows.backend.facade.contracts import FunctionTemplateSchema, WorkflowTemplate+from products.workflows.backend.facade.contracts import (+ FunctionTemplateSchema,+ WorkflowTemplate,+ WorkflowTemplateNotFound,+)from products.workflows.backend.facade.enums import HogFlowTemplateExitCondition, HogFlowTemplateScopefrom products.workflows.backend.models.hog_flow.hog_flow_template import HogFlowTemplatefrom products.workflows.backend.templates import get_global_template_by_id, load_global_templates@@ -29,10 +33,6 @@ WRITABLE_TEMPLATE_FIELDS = frozenset()-class WorkflowTemplateNotFound(Exception):- pass--def _to_template(template: HogFlowTemplate) -> WorkflowTemplate:return WorkflowTemplate(id=template.id,diff --git a/products/workflows/package.json b/products/workflows/package.jsonindex e250226db894..f4cfe23cb6f7 100644--- a/products/workflows/package.json+++ b/products/workflows/package.json@@ -1,7 +1,8 @@{"name": "@posthog/products-workflows","scripts": {- "backend:test": "pytest -c ../../pytest.ini --rootdir ../.. backend/ -v --tb=short"+ "backend:test": "pytest -c ../../pytest.ini --rootdir ../.. backend/ -v --tb=short",+ "backend:contract-check": "echo 'Contract files unchanged'"},"dependencies": {"@posthog/quill-charts": "workspace:*",diff --git a/products/workflows/turbo.json b/products/workflows/turbo.jsonnew file mode 100644index 000000000000..156e9dd206df--- /dev/null+++ b/products/workflows/turbo.json@@ -0,0 +1,19 @@+{+ "extends": ["//"],+ "tasks": {+ "backend:contract-check": {+ "inputs": [+ "backend/facade/**",+ "backend/presentation/**",+ "backend/routes.py",+ "backend/webhook_consumers.py",+ "backend/tasks/**",+ "backend/max_tools.py",+ "backend/models/**",+ "backend/migrations/**"+ ],+ "outputs": [],+ "cache": true+ }+ }+}diff --git a/pyproject.toml b/pyproject.tomlindex c0983a1a632e..52cb8ba571e8 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -712,12 +712,6 @@ ignore_imports = [# (warehouse_sources, data_modeling, data_tools, cdp, revenue_analytics, batch_exports)# directly. Thin each viewset to parse -> facade -> serialize and delete each entry.# backend:contract-check stays off until this list is empty.- # TODO: workflows presentation wave — the moved viewsets still reach in-product internals and- # sibling products (cdp, cohorts, feature_flags, messaging) directly. Thin each viewset to- # parse -> facade -> serialize and delete each entry. backend:contract-check stays off until- # this list is empty. Only delete entries here: a new import from these views goes through- # the facade.- "products.workflows.backend.presentation.views.hog_flow -> products.messaging.backend.api.message_templates",# TODO: access-control presentation wave — the consolidated RBAC viewsets carry their ORM# access with them. Thin them to parse -> facade -> serialize and delete each entry."products.access_control.backend.presentation.access_control -> products.access_control.backend.models.access_control",diff --git a/tools/hogli-commands/hogli_commands/product/isolation.py b/tools/hogli-commands/hogli_commands/product/isolation.pyindex 8b57a8438c54..7451c676eed2 100644--- a/tools/hogli-commands/hogli_commands/product/isolation.py+++ b/tools/hogli-commands/hogli_commands/product/isolation.py@@ -589,6 +589,7 @@ CARVE_OUTS: frozenset[tuple[str, str]] = frozenset({("customer_analytics", "TeamCustomerAnalyticsConfig"),("tasks", "Task"),+ ("workflows", "TeamWorkflowsConfig"),})