N
Novu3mo ago
Rainmaker

Next step is skipped as well when the first one is skipped

Hello everybody! I'm having a strange issue with the code-first workflow. I have a workflow with 2 steps: send-email and send-sms. Each one should be dispatched only if the payload.type matches with itself, for example:
{
"type": "email"
}
{
"type": "email"
}
It should send the email and skip the SMS, and:
{
"type": "sms"
}
{
"type": "sms"
}
It should send the SMS and skip the email. It turns out that when I trigger the workflow to send the email, the SMS is skipped correctly, but when I trigger the same to send the SMS, both email and SMS are skipped. If I invert the steps orders, the problem will be inverted as well, with SMS being sent as expected, but the email will be skipped when should be sent. I tested the same flow in Local Studio, also in a deployed environment, triggering through the Novu Dashboard, but I was unsuccessful in identifying the reason. The single thing that I'd identified it's in the Bridge API log the following error: Failed to hydrate stepId: 'send-sms', after that, Novu tries to send again, and then the bug occurs. I'm sure the issue isn't related to the workflow code to render the body, because I tested with static text, both for email and SMS. Could you help me to understand the issue, my mistake, or if it's really a bug? Thank you.
12 Replies
Rainmaker
Rainmaker3mo ago
Environment ID: 66a79f82dfafba8038bc33a4
Pawan Jain
Pawan Jain3mo ago
@Rainmaker Thanks for sharing the issue in detail. It helps in debugging. Can you please share the code snippet you are using for above workflow?
Rainmaker
Rainmaker3mo ago
Sure @Pawan Jain It's something like that:
import { workflow } from "@novu/framework";
import { payloadSchema } from "./schemas";

export const verificationCode = workflow(
"verification-code",
async ({ step, payload }) => {
await step.email(
"send-email",
() => ({
subject: 'Your verification code',
body: `Hello! This is your verification code: ${payload.code}`,
}),
{
skip: () => payload.type !== "email",
},
);

await step.sms(
"send-sms",
() => ({
body: `Your verification code is: ${payload.code}`
}),
{
skip: () => payload.type !== "sms",
},
);
},
{ payloadSchema },
);
import { workflow } from "@novu/framework";
import { payloadSchema } from "./schemas";

export const verificationCode = workflow(
"verification-code",
async ({ step, payload }) => {
await step.email(
"send-email",
() => ({
subject: 'Your verification code',
body: `Hello! This is your verification code: ${payload.code}`,
}),
{
skip: () => payload.type !== "email",
},
);

await step.sms(
"send-sms",
() => ({
body: `Your verification code is: ${payload.code}`
}),
{
skip: () => payload.type !== "sms",
},
);
},
{ payloadSchema },
);
Thank you for your response.
Pawan Jain
Pawan Jain3mo ago
@Rainmaker I can reproduce the bug. Sharing it with team
Linear
Linear3mo ago
Found issue NV-4169.
NV-4169 - bug: skip with each step in workflow is not working as expected
What? Test workflow | Novu - 2 August 2024
export const verificationCode = workflow(
"verification-code",
async ({ step, payload }) => {
console.log("payload ==>", payload);
await step.email(
"send-email",
() => ({
subject: "Your verification code",
body: `Hello! This is your verification code: ${payload.code}`,
}),
{
skip: () => payload.type !== "email",
}
);

await step.inApp(
"send-in-app",
() => ({
body: `Your verification code is: ${payload.code}`,
}),
{
skip: () => payload.type !== "sms",
}
);
},
{
payloadSchema: z.object({
code: z.string(),
type: z.enum(["email", "sms"]).default("email"),
}),
}
);
export const verificationCode = workflow(
"verification-code",
async ({ step, payload }) => {
console.log("payload ==>", payload);
await step.email(
"send-email",
() => ({
subject: "Your verification code",
body: `Hello! This is your verification code: ${payload.code}`,
}),
{
skip: () => payload.type !== "email",
}
);

await step.inApp(
"send-in-app",
() => ({
body: `Your verification code is: ${payload.code}`,
}),
{
skip: () => payload.type !== "sms",
}
);
},
{
payloadSchema: z.object({
code: z.string(),
type: z.enum(["email", "sms"]).default("email"),
}),
}
);
Status
Triage
Workflows
Rainmaker
Rainmaker3mo ago
Thank you @Pawan Jain . Just curious, is there a ETA to fix bugs like that?
Pawan Jain
Pawan Jain3mo ago
@Rainmaker I will keep you updated on this. I hope it to be fixed end of this week
Rainmaker
Rainmaker3mo ago
Hello @Pawan Jain Do you have any news? Thanks.
Novu_Bot
Novu_Bot3mo ago
@Rainmaker, you just advanced to level 1!
Pawan Jain
Pawan Jain3mo ago
@Rainmaker Richard from our team have raised a PR for this https://github.com/novuhq/novu/pull/6371
Rainmaker
Rainmaker3mo ago
Thank you so much @Pawan Jain When it's released, I'll be back to you if it worked.
Pawan Jain
Pawan Jain2mo ago
@Rainmaker This bug is not fixed. Can you please retry?
Want results from more Discord servers?
Add your server