Database Trigger User After Change Working, Before Change not Working

I have an odd situation using database triggers when a user closes their account (goes inactive rather than deletes it).

I run a database trigger of this event, which triggers as expected; however, the system then searches for their other content to make some changes (i.e. Created By = User After/Before Change). This also works (to a degree).

The problem is that searching for their content using User Before Change returns nothing, but searching for their content using User After Change returns the content as expected.

So while I have a simple enough workaround here, this will be a problem when I do the same when a user is deleted, as their User After Change will be nothing.

Am I doing something wrong here or is Bubble?

This sounds expected if the user was just created, so like if they just signed up then Before Change would be empty. Before of course is before, but searches are happening “After” regardless since you can’t “Search as if I was back in time”

Yes this is also expected cause the won’t exist anymore after the change. In this case I would split this into a chain of workflows where you delete all the child data first, then the very last step after everything is to delete the User.

Or just don’t delete them and make some yes/no field saying they are “deleted”

1 Like

Thanks @tylerboodman - I probably wasn’t clear enough in my initial problem statement.

  • I have a user which I switch to a “closed” state - they exist, they just have an update to their DB entry state = closed
  • This triggers an update to their existing content (e.g sets it to visibility = hidden)
  • I can search for their content using user = user now, but searching for their content with user = user before change turns up nothing.
  • They fully existed creating content before they were updated, so why does user = user before change result in an empty search.

So the question is why does a search using user = user before change for content created by that user while they existed just 2 seconds ago turn up empty?

Hmm… yea if it is the same existing User before and after then that doesn’t make sense…

The only things I can think of is make sure your database trigger isn’t falsy triggering, like on a user sign up if they are defaulted to “closed” then that would also trigger this unless you have the additional check that they weren’t empty before.

Maybe screenshots would help see if anything seems off, otherwise might need to ask Bubble to look at it…

I found some interesting results in the server logs, which I’ll send to bubble. This was from deleting a user, and interestingly “User Now” (deleted) works, and still “User Before Change” does not.

Here I user “User Before Change” to delete Engagement Tags and “User Now” to delete “Professional Details”