: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(workflows): resolve variables in ticket tag inputs (#62359)
Meikel Ratzc353ffdd56a6
diff --git a/nodejs/src/cdp/services/hogflows/__snapshots__/hogflow-manager.service.test.ts.snap b/nodejs/src/cdp/services/hogflows/__snapshots__/hogflow-manager.service.test.ts.snapindex f5616efdf3e4..9f0bf29f3890 100644--- a/nodejs/src/cdp/services/hogflows/__snapshots__/hogflow-manager.service.test.ts.snap+++ b/nodejs/src/cdp/services/hogflows/__snapshots__/hogflow-manager.service.test.ts.snap@@ -65,6 +65,7 @@ exports[`HogFlowManager returns the hog flow 1`] = `},"trigger_masking": null,"updated_at": "UPDATED_AT",+ "variables": null,"version": 1,},{@@ -130,6 +131,7 @@ exports[`HogFlowManager returns the hog flow 1`] = `},"trigger_masking": null,"updated_at": "UPDATED_AT",+ "variables": null,"version": 1,},]diff --git a/nodejs/src/cdp/services/hogflows/hogflow-manager.service.ts b/nodejs/src/cdp/services/hogflows/hogflow-manager.service.tsindex a319fd1576e5..ea8224fdbc90 100644--- a/nodejs/src/cdp/services/hogflows/hogflow-manager.service.ts+++ b/nodejs/src/cdp/services/hogflows/hogflow-manager.service.ts@@ -23,6 +23,7 @@ const HOG_FLOW_FIELDS = ['actions','abort_action','billable_action_types',+ 'variables',]export type HogFlowTeamInfo = Pick<HogFlow, 'id' | 'team_id' | 'version'>diff --git a/nodejs/src/cdp/templates/_destinations/posthog_conversations/posthog-update-ticket.template.ts b/nodejs/src/cdp/templates/_destinations/posthog_conversations/posthog-update-ticket.template.tsindex 574ead449b22..0db129623356 100644--- a/nodejs/src/cdp/templates/_destinations/posthog_conversations/posthog-update-ticket.template.ts+++ b/nodejs/src/cdp/templates/_destinations/posthog_conversations/posthog-update-ticket.template.ts@@ -149,7 +149,8 @@ return response.bodylabel: 'Tags',secret: false,required: false,- description: 'Tags to apply to the ticket. Leave empty to keep current tags.',+ description:+ 'Tags to apply to the ticket. Each tag supports variable templating, e.g. {event.properties.region}. Leave empty to keep current tags.',},{key: 'tags_mode',diff --git a/nodejs/src/cdp/workflows-e2e.test.ts b/nodejs/src/cdp/workflows-e2e.test.tsindex f24ad0e8ef98..f62365a959fe 100644--- a/nodejs/src/cdp/workflows-e2e.test.ts+++ b/nodejs/src/cdp/workflows-e2e.test.ts@@ -1027,6 +1027,111 @@ describe.each(['postgres-v2' as const, 'postgres' as const])('Workflows E2E (%s)expect(mockPersonRepo.fetchDistinctIdsForPersons).not.toHaveBeenCalled()})})++ describe('posthog_ticket_tags input resolves templated values per element', () => {+ // Regression guard for the templating opt-in in posthog/cdp/validation.py.+ // Reproduces the real user-reported case: a ticket tag set to+ // `zendesk/{variables.zendesk_ticketid}` used to ship to the runtime as+ // a literal placeholder string (because the type wasn't on the bytecode+ // opt-in list), so the ticket ended up tagged with the raw template text+ // instead of "zendesk/12345". The fix puts the per-element bytecode that+ // `generate_template_bytecode` already emits for lists into a shape that+ // `formatHogInput` can walk element-by-element.+ beforeEach(async () => {+ await insertHogFunctionTemplate(hub.postgres, {+ id: 'template-workflows-e2e-tags',+ name: 'Workflows E2E Tags',+ code: `fetch(inputs.url, { 'method': 'POST', 'body': jsonStringify(inputs.tags) });`,+ inputs_schema: [+ { key: 'url', type: 'string', required: true },+ { key: 'tags', type: 'posthog_ticket_tags', required: true },+ ],+ })++ const hogFlow = new FixtureHogFlowBuilder()+ .withTeamId(team.id)+ .withStatus('active')+ .withWorkflow({+ actions: {+ trigger: trigger(),+ function_1: {+ type: 'function',+ config: {+ template_id: 'template-workflows-e2e-tags',+ inputs: {+ url: { value: 'https://example.com/tags' },+ tags: {+ // What the Python serializer now produces for a+ // `posthog_ticket_tags` value like+ // `["zendesk/{variables.zendesk_ticketid}"]`:+ // one outer array, one inner bytecode per element.+ // Inner bytecode is a concat of the literal prefix+ // and a variables.* field access — same shape Django+ // emits today for other templated string inputs+ // (cf. the production `text` input bytecode).+ value: ['zendesk/{variables.zendesk_ticketid}'],+ templating: 'hog',+ bytecode: [+ [+ '_H',+ 1,+ 32,+ 'zendesk/',+ 32,+ 'zendesk_ticketid',+ 32,+ 'variables',+ 1,+ 2,+ 2,+ 'concat',+ 2,+ ],+ ],+ },+ },+ },+ },+ exit: exitAction(),+ },+ edges: [+ { from: 'trigger', to: 'function_1', type: 'continue' },+ { from: 'function_1', to: 'exit', type: 'continue' },+ ],+ })+ .build()+ // Workflow-defined variable with a default — populated into state.variables+ // by createHogFlowInvocation, so the function action sees it via globals.variables.+ // In a real workflow the value would be set by an earlier `Get ticket` action's+ // output_variable; for this test we pre-seed via the default to keep it focused.+ hogFlow.variables = [+ { key: 'zendesk_ticketid', type: 'string', label: 'Zendesk ticket id', default: '12345' },+ ]+ await insertHogFlow(hub.postgres, hogFlow)++ globals = createGlobals()+ })++ it('resolves zendesk/{variables.zendesk_ticketid} per element', async () => {+ await triggerWorkflow(globals)++ await waitForExpect(() => {+ expect(mockFetch).toHaveBeenCalledTimes(1)+ }, 10000)++ // The body proves the full chain end-to-end: per-element bytecode →+ // formatHogInput recurses into the list → executes against globals+ // populated with workflow variables → concat produces "zendesk/12345".+ // Pre-fix behaviour would emit `["zendesk/{variables.zendesk_ticketid}"]`.+ expect(mockFetch).toHaveBeenCalledWith(+ 'https://example.com/tags',+ expect.objectContaining({+ body: JSON.stringify(['zendesk/12345']),+ method: 'POST',+ })+ )+ })+ })})// Email queue routing is postgres-v2 only — the email worker reschedules jobsdiff --git a/posthog/cdp/test/test_validation.py b/posthog/cdp/test/test_validation.pyindex 8b1717c849d6..e41416a7e11a 100644--- a/posthog/cdp/test/test_validation.py+++ b/posthog/cdp/test/test_validation.py@@ -663,3 +663,49 @@ class TestHogFunctionValidation(ClickhouseTestMixin, APIBaseTest, QueryMatchingTinputs = {"non_failure_status_codes": {"value": value}}with self.assertRaises(ValidationError):validate_inputs(inputs_schema, inputs)++ def test_posthog_ticket_tags_schema_type_is_valid(self):+ inputs_schema = [+ {+ "key": "tags",+ "type": "posthog_ticket_tags",+ "label": "Tags",+ "required": False,+ }+ ]+ validated = validate_inputs_schema(inputs_schema)+ assert validated[0]["type"] == "posthog_ticket_tags"+ assert validated[0]["key"] == "tags"++ @parameterized.expand(+ [+ # Reproduces the original user report: a mixed literal prefix plus a workflow variable.+ ("template_workflow_variable", ["zendesk/{variables.zendesk_ticketid}"]),+ # Pure event-property substitution.+ ("template_event_property", ["{event.properties.region}"]),+ # Literal-only list still gets per-element bytecode — back-compat path.+ ("literal_only", ["top_20"]),+ # Mix of literal and templated tags in a single list.+ ("mixed_literal_and_templated", ["plan_enterprise", "{event.properties.region}"]),+ ]+ )+ def test_posthog_ticket_tags_compiles_per_element_bytecode(self, _name, value):+ # Regression guard for the InputsItemSerializer opt-in. Before posthog_ticket_tags+ # was added to the list of types that go through generate_template_bytecode, list+ # values shipped without a `bytecode` field, so the Node runtime had nothing to+ # interpolate against and tags ended up containing the literal placeholder text+ # (e.g. a tag literally named `zendesk/{variables.zendesk_ticketid}`).+ inputs_schema = [{"key": "tags", "type": "posthog_ticket_tags", "required": False}]+ inputs = {"tags": {"value": value}}+ validated = validate_inputs(inputs_schema, inputs)++ bytecode = validated["tags"].get("bytecode")+ assert bytecode is not None, "tags input must have bytecode after the opt-in"+ assert isinstance(bytecode, list), "list values compile to a list of per-element bytecode"+ assert len(bytecode) == len(value), "one bytecode entry per tag element"+ for entry in bytecode:+ assert isinstance(entry, list) and entry[:2] == ["_H", HOGQL_BYTECODE_VERSION], (+ "each element is itself a Hog bytecode array"+ )+ # The original value round-trips so the UI can still render the templated source string.+ assert validated["tags"]["value"] == valuediff --git a/posthog/cdp/validation.py b/posthog/cdp/validation.pyindex 9ad3734ec021..6d704cd5578e 100644--- a/posthog/cdp/validation.py+++ b/posthog/cdp/validation.py@@ -344,6 +344,7 @@ class InputsItemSerializer(serializers.Serializer):"json","email","native_email",+ "posthog_ticket_tags",] or (item_type == "boolean" and isinstance(value, str))if value_is_transpiled:if item_type in ("email", "native_email") and isinstance(value, dict):