Workflow runs when it shouldn't, and runs out of order

I am having issues with a workflow that runs when it shouldn’t.

  1. When Page is loaded I have the workflow set up to set a few unrelated element states, and then it calls a custom workflow called Check User Exists

  2. Check User Exists then uses the LocalStorage plugin’s action called Get LocalStorage. When LocalStorage’s values are 0, it will run a custom workflow called Create User

  1. Create User looks at a data type called WF User and increments the User ID by +1, so that the next user will have a different User ID, then saves a new WF User with the incremented User ID, and saves that User ID using LocalStorage plugin.

The problem is that this Create User workflow seems to run no matter if the LocalStorage comes back empty or with a value already present. In fact, when I put the application is debug mode and turn on step-by-step, the Create User workflow seems to run INSTANTLY when the page loads, before the debug shows any other workflows having run. When I step through the workflows, it stops before running Create User (because the LocalStorage value comes back not empty).

Why in the world is this workflow running when it shouldn’t? I’m pulling my hair out over here!

Thanks for any help.

Edit to add that I broke this up into separate custom workflows to make sure there weren’t issues with workflow steps running before a previous step completed. Didn’t help.

This hidden post might answers some of your questions :slightly_smiling_face:
It should be on the documentation.

General rules about how workflows run:

  • Frontend workflow actions run in order but the next action does not wait on the previous action to be complete before triggering.
  • Backend workflows are triggered as soon as the workflow is triggered, independently from steps. For example, a ‘Schedule API Workflow’ action will be triggered as soon as the workflow is triggered even if it is placed last in the workflow action sequence.
  • Custom events run in sequence, not parallel. If Workflow 1 triggers a custom event that starts Workflow 2, Workflow 2 will complete before the remaining actions in Workflow 1 run.
  • Searches aren’t always immediately updated with new data. So if you create a new item, and then try to retrieve it via search, it may or may not work; you should not rely on this.
  • Retrieving a thing from “result of step X” where step X is the “Create…” step should always be safe.

Workarounds to help achieve workflow consistency:

  • When a workflow trigger (eg. a button) can have multiple results based on conditions, it is safer to create multiple workflows and place the conditions at the workflow level instead of creating one workflow with all possible actions and placing the conditions at the action level.
  • In a workflow with two actions, if Step 2 is using a condition based on a search depending on data manipulated in Step 1, then Step 1 should be implemented into a custom event to make sure it is finished before moving on to Step 2.
  • If a backend workflow should be triggered after other steps in the workflow, then it should be implemented in a custom event placed after the steps that need to come first.
  • The safest way to use data from one step to another is to use the “result of step X” operators instead of searches.
  • We do not offer the explicit ability for an action to wait for a workflow to be over before moving on to the next step; however, using ‘add a pause before next action’ action is usually an effective workaround.
1 Like

Thanks; however, that is exactly the post I read that made me break the workflow up into several custom events.

Where I’m very confused is that when I run step-by-step debug mode, this custom event (including the Create WF User… action) never appears to run in the debug console, and it runs before any other action runs, even though it should be the last step. It makes zero sense at all, even taking into account the workflow quirks described in that post.

Here is a video that shows the issue (sorry for the audio quality):

I’ve had similar issues in the past with reading cookies… what it usually comes down to is it takes some time to read the cookie’s value (in your case Local Storage), so relying on that data for conditions in the same workflow is never going to be reliable…

Presumably in your case, when the workflow runs, the count of Local Storage A’s values will be 0 (regardless of whether or not it later has a value assigned to it) as, even if it will have a value a few milliseconds later, it takes some time to establish that… by which time the second action will have already run, as the condition was met… which would explain why the workflow action runs every time.

If you want the Trigger Create User action to only run if the Local Storage A’s value count is 0 (but not because it hasn’t yet been checked) you’ll probably need to use some additional custom events…

maybe put the Get Local Storage action into a custom event, and set a (yes/no) state once that custom event has finished running (regardless of whether there were any values or not) - then run a conditional workflow when that state value is set to ‘Yes’ .

That way you know for sure that the Local Storage A Value’s count is 0 because there aren’t any values, and not just because it’s taking some time to establish whether it has any values or not (during which time its value count will be 0 anyway).

1 Like

Thanks—I am trying to wrap my head around this (and some other issues) and will update here if I make any progress.

The thing that is still confusing the heck out of me is WHY does the Create WF User… action run as soon as the page is loaded? You can clearly see it happening in the YouTube video I posted. This action runs before any of the conditions have been tested re: LocalStorage A. Makes no sense to me at all.

As explained in the post linked to by @vnihoul77, workflow actions don’t wait until the previous one has finished…

So in this case, the action to schedule the Custom Event runs more-or-less as soon as the workflow starts - that’s how it works.

1 Like

But even in step-by-step debug mode? Shouldn’t that only cause the item to run when I click “Next Step”?

And even then, it never shows it running in the step-by-step debugger. Surely that isn’t correct…?

The Debugger is a great tool for checking many things…

But it’s not much use for checking the order of workflow actions.

(in many cases, the workflow actions will have run long before you actually click the next button - even to the point that conditions will show up as being true/false in the debugger, even if they were the opposite when the actions actually ran - so often the debugger, in step by step mode, will show actions as running that never actually ran, and vice versa, as the condition was evaluated differently when the workflow ran compared to when the next button was clicked).

So the debugger isn’t much help in these cases.

1 Like

I have been using Bubble for a few years now (I’ve even developed some plugins) and this is the first time I’ve ever seen something run without even showing up in the debugger. Especially an item inside of a custom event. I even added a breakpoint to the Create WF User… action and it still doesn’t behave like literally every other app I’ve ever built behaves. Every other action in every other workflow in this application shows up except this one that is behaving oddly. I feel like this is a bug, not user error (although I don’t necessarily discount my own ability to screw things up).

If I take this same action (Create WF User…) and tie it to a button being pressed, it shows up in the debugger. If I had 50 actions to my workflows, all 50 show up except this one. And none of them run BEFORE I click “Next” in the debugger in step-by-step mode.

I appreciate your assistance, but I’m sort of beyond accepting this as “workflows don’t necessarily run in order” as the explanation for the very odd behavior I’m seeing. It just doesn’t make sense, even taking the quirks of Bubble into account.

(Adam, my apologies for doubting you here, I was frustrated!)

Nope :slight_smile:

P.S. Also debugger is almost useless if you are deleting things and some related data/connections.

1 Like

Wow. Okay, so that’s new info for me. Thus far, I guess I just hadn’t run into any issues with the debugger like this.

I’m going to circle back and try adding some 10-20 second delays between steps and see if I can figure out which actions are taking so long to execute and having my conditions be in a state where they allow the workflow to proceed.

Thanks all for your help. Back into the headache I go.

Also don’t forget to check server logs. Sometimes they can be more helpful than debugger.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.