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(workflows): stop double-quoted liquid strings breaking emails (#113274)

Chris Shine0137b94b6b73
diff --git a/nodejs/src/cdp/services/hog-inputs.service.test.ts b/nodejs/src/cdp/services/hog-inputs.service.test.ts
index 263d7e1741ff..de7891268312 100644
--- a/nodejs/src/cdp/services/hog-inputs.service.test.ts
+++ b/nodejs/src/cdp/services/hog-inputs.service.test.ts
@@ -361,6 +361,25 @@ describe('Hog Inputs', () => {
)
})
+ it('drops the editor design from a liquid email instead of rendering it', async () => {
+ const tag = '{% if event.event == "test" %}Hi{% endif %}'
+ hogFunction.inputs = {
+ email: {
+ templating: 'liquid',
+ value: {
+ to: { email: '{{person.properties.email}}' },
+ html: `<p>${tag}</p>`,
+ design: { body: { rows: [{ values: { textJson: JSON.stringify({ text: tag }) } }] } },
+ },
+ },
+ }
+ hogFunction.inputs_schema = [{ key: 'email', type: 'native_email', required: true, templating: true }]
+
+ const inputs = await hogInputsService.buildInputs(hogFunction, globals)
+ expect(inputs.email.html).toEqual('<p>Hi</p>')
+ expect(inputs.email.design).toBeUndefined()
+ })
+
it('resolves push subscription inputs without a valid integration', async () => {
const hogFunction = createHogFunction({
id: 'hog-function-1',
diff --git a/nodejs/src/cdp/services/hog-inputs.service.ts b/nodejs/src/cdp/services/hog-inputs.service.ts
index a2ccea6aaa56..943d3205ca75 100644
--- a/nodejs/src/cdp/services/hog-inputs.service.ts
+++ b/nodejs/src/cdp/services/hog-inputs.service.ts
@@ -15,6 +15,8 @@ import { RecipientTokensService } from './messaging/recipient-tokens.service'
export const EXTEND_OBJECT_KEY = '$$_extend_object'
+const EMAIL_INPUT_TYPES = ['native_email', 'email']
+
export class HogInputsService {
constructor(
private integrationManager: IntegrationManagerService,
@@ -45,11 +47,24 @@ export class HogInputsService {
// One budget for the whole invocation, so many small liquid leaves cannot add up to a stall.
const liquidBudget = new LiquidRenderBudget()
+ // Build a lookup of schema types for rendering and post-render coercion
+ const schemaTypes: Record<string, string> = {}
+ for (const schema of hogFunction.inputs_schema ?? []) {
+ schemaTypes[schema.key] = schema.type
+ }
+
const _formatInput = async (input: CyclotronInputType, key: string): Promise<any> => {
const templating = input.templating ?? 'hog'
if (templating === 'liquid') {
- return formatLiquidInput(input.value, newGlobals, key, liquidBudget)
+ let value = input.value
+ // `design` is the email editor's state and is never sent. Its JSON-encoded strings escape quotes
+ // as \", which Liquid cannot parse. validation.py drops it the same way before it compiles hog.
+ if (EMAIL_INPUT_TYPES.includes(schemaTypes[key]) && value?.design !== undefined) {
+ const { design: _design, ...rest } = value
+ value = rest
+ }
+ return formatLiquidInput(value, newGlobals, key, liquidBudget)
}
if (templating === 'hog' && input?.bytecode) {
try {
@@ -63,9 +78,7 @@ export class HogInputsService {
}
// Add unsubscribe url if we have an email input here
- const emailInputSchema = hogFunction.inputs_schema?.find((input) =>
- ['native_email', 'email'].includes(input.type)
- )
+ const emailInputSchema = hogFunction.inputs_schema?.find((input) => EMAIL_INPUT_TYPES.includes(input.type))
const emailInput = hogFunction.inputs?.[emailInputSchema?.key ?? '']
if (emailInputSchema && emailInput) {
@@ -86,12 +99,6 @@ export class HogInputsService {
}
}
- // Build a lookup of schema types for post-render coercion
- const schemaTypes: Record<string, string> = {}
- for (const schema of hogFunction.inputs_schema ?? []) {
- schemaTypes[schema.key] = schema.type
- }
-
const orderedInputs = Object.entries(inputs ?? {}).sort(([_k1, input1], [_k2, input2]) => {
return (input1?.order ?? -1) - (input2?.order ?? -1)
})