Thing not getting created in DB even though Unique ID gets generated

I have faced this issue quite often, and it keeps reappearing.

What happens is I create a thing in a flow, and note its unique ID. Now later in another workflow I try to search for that item with the unique ID, I don’t find that item in the DB. In fact if I pause the workflow using breakpoint in the code, and check in the DB right after creation, I don’t see that thing in the DB.

I am getting the ID from Bubble, so it must be creating it, right?

What can cause this to happen?

Here are the screenshots that show this:

Here it is shown that thing is created and in next step its ID is shown:

However, at the same time same thing when I search in DB is not found:

Later in next workflow when I try to access the same thing with same ID, I find nothing.

This is Search

And here the item is empty

There could be a few things going on here. If you’re ok to share read access to your app, we can diagnose the cause.

I can share the app, but I might have to explain quite a bit to you to explain what is what. Is that fine?

Might not be necessary fo the explanations. I have a couple of ideas as to what might be the cause. If I get stuck in my problem solving I’ll let you know.

Okay. Here you go:

Error is in first workflow.

Right now I have added step 2 and step 3 to debug the issue and send me email when DB search fails on not finding element in the DB. That is causing another issue of debugger breaking. I have reported that as a bug. And I might remove these steps until Bubble tells me what is going wrong there.

Screenshots that I had posted were for the workflow “Restore Need” which is called in step 8 of first workflow.

First question:
Why have you broken the create and make changes steps into 2? Why not just set all the fields in the create step?

So I had it in one step earlier. This is all for the debugging I do.

Two reasons for breaking into two:

  1. It helps me see in the next step in debugger that entity was actually created
  2. I was copying some values from the entity that is being passed to the workflow. Now due to this DB thing not getting updated, sometimes the entity passed to the workflow was this non existent entity, and non existent thing’s values were being copied. I suspected that that might be causing some issues and then broke into two. It took me some time to break into two actually.

So the new need is automatically created when the page is loaded?

No. It is created only if there was a temp need id stored in the cookie. If there is a temp need id in the cookie then I create a new need and copy the value from the need of which ID was stored in the cookie.

I have done this to be able to preserve form filled by user before logging in as when they submit the form i force them to login.

Also, if the temp need in the cookie is created by same as user as current user, then I assume to the be the case of a logged in user going back to the first step and trying to edit it. In that case “edit need” is set “yes”, and then also new need is not created.

I haven’t worked with cookies before, but I have similar process flow and don’t need / use cookies. I just use a combination of the form values and custom states. Not sure all that complexity is necessary. What will you do if user says they don’t want to enable cookies?

If cookies are disabled, they have to just fill the form again. But mostly people agree to it, so it is okay.

How do you achieve the same workflow without cookie?

All the form inputs are still available yes?

I am doing it as per the recommendation in this thread: How to attach anonymous data to existing user after they log in?

Form fields are available, but when user logs in after filling the form before being logged in, then to get that data you have to have some linkage between non logged in and logged in user.

But isn’t it the issue of a thing getting created but not reflecting in DB? Cookies are storing their values fine.

fair call. I’ll get back on trying to figure out why the thing isn’t being created as expected. But I’ll just say this… Whenever I have over complicated how I work with data, it creates downstream problems.

For example, I wonder if the issue is being caused by privacy rule conflicts with the logged in user and referencing that data stored in the cookie. Tough to diagnose this, but that may be something for you to explore.

I had gone that route.

Two things there:

  1. I see no other way of specifying what I want in privacy rules. I did what all I could do to my common sense.
  2. I have seen this behaviour of data not storing even if I remain logged in and fill the form and come back to this page after going to step 2. So, both the temp need and new need are created by me only. No issue of non logged in and logged in user. However, even there the thing that I created doesn’t register in DB.

Nobody wants to complicate things. We all do as per the constraints. Here constraint is Bubble works in a certain way only to implement certain things. And other constraint which I have put on myself is that I don’t want to force users to login before filling the form.

Btw, cookie is just storing the ID of a thing that was created earlier. Cookie is not storing the thing itself.