Update database seems to always be 1 behind

I have a function to allow user to upload a photo and it will automatically grab the photo ID and update the photo field in my database. When user uploads a file, it will trigger uploadPhoto() and then updatePhoto().

uploadPhoto():

updatePhoto():
image

When both triggers happen, the K-V pair for photo in updatePhoto() is correct and matches the file ID of the last upload in Retool Storage. The issue is, the RetoolData database is not updating to the newly uploaded file ID. It keeps updating to the ID of the photo before the upload.

Example of user uploading file and what KV pair for photo returns
image

Proof that it's correct (it matches the newly uploaded photo's ID):

However, Retool's Databse keeps storing test4's photo as test3's photo ID (which is data[1] as shown in above pic)

The same will happen if I upload a photo for test5. It will store the file ID of photo4 into database instead of the new photo5 ID.

I also have the "run this query on page load" checkbox checked in updatePhoto. Not sure what else to try at this point.

Hello @kw9521, have you tried triggering the 2nd query on the event handler of the first, like you are doing with "newPhoto" on the first image?