Trigering queries in parallel make them overwrite each other

EDIT: Because the stupid limitation of not being able to post more than one image I had to break the post into 3 posts
Hello.
I am performing a very basic JS task and I am facing what I think it is a bug on the platform. I have a code that triggers a query several times with different parameters. The queries are supposed to run in parallel, but if I do that then all the queries are triggered with the same parameters. It looks like triggering them too close to each other makes the new trigger to overwrite the parameters of the previous query and they are all executed with the same parameters.

This is the code:

const data = await GetAccountPayments.trigger({additionalScope: { page: 0 }})
if(data.totalPages <= 1) return data.content
const queries = _.range(1,data.totalPages).map(
	    (idx) => GetAccountPayments.trigger({additionalScope: { page: idx }}).then(data => ({data, idx}))
  )

return Promise.all(queries).then(result => {
  console.log({result})
  return [data, ...result]
})

As you can see, first I trigger the query and wait for it, that works perfectly, then inside the loop when I trigger them all in parallel they all get the same parameters, that's why I know the bug is they overwrite each other, because if you do them sequentially it just works.
This is the first query with the correct first parameter (the 0) on the queryParams[2]

However, all the next queries (in this case another 2) they all are executed with the same query params a 2:

Also I'm 100% confident that the bug is on the platform because the console is correctly reporting that the correct extra parameters are being provided:

image

Having to fire all the queries in series it is a huge performance hit compared to running them all in parallel.

Just modified my code a bit to run all the queries in series and it works correctly:

const data = await GetAccountPayments.trigger({additionalScope: { page: 0 }})

const queries = _.range(1, data.totalPages).reduce((prev, idx) =>
	    prev.then(
                          (val) => GetAccountPayments.trigger({additionalScope: { page: idx }})
                                                                            .then(newData => val.concat(newData))
               )
  , Promise.resolve([data])
)

return queries.then(result => {
  console.log({result})
  return result
})

THIS IS NOT A SOLUTION TO MY PROBLEM it is just a demonstration of why the problem happens, this is only a workaround

Hey Danielo,

I tried reproducing this on my end using just a simple rest query to postman-echo, and both the serial and parallel versions worked fine. Are you able to share a screenshot of your GetAccountPayments query? It seems possible that there is something odd with that query which could be resulting in the behavior you are seeing.

Hello @mark
This is the query on the query library:

And this is how it looks like on the app:

Hmm, nothing stands out as particularly strange with those queries to me. Would you be able to share an export the app so that I can investigate a bit more? You can upload it here: https://www.dropbox.com/request/UiZcrop9XUWmcKW2BlXX

(@Danielo just updated the settings to allow more images, sorry about that)

I asked support on the app to review this thread and I granted them permissions to inspect my account. Is that enough?

Hey Danielo, looks like another support team member was asking some questions in that ticket you started. Feel free to respond there, or open another ticket. We should be able to help you out there!

Oh really?I can't see any question. Can you point me to them?

It should be in your chat history when you are logged into Retool. If you don't see it, feel free to write in via the chat again to start a new ticket and we can go from there.

I am running into the exact same issue. Trying to dynamically invoke a trigger in parallel using the results from a previous trigger, but it is executing with the same additionalScope parameters despite being called with different ones each time.

I could only get this to work serially but is not a final solution for me either.

Help! =(

Just wanted to provide a quick update here, while continuing to investigate this issue with @Adub we were able to locate a bug with the query library, where variables defined in the query library queries are overwriting all instances of that variable in additionalScope used in queries in an app. Our engineering team will be investigating this further and hope to put out an update within the next few weeks to address this. I will update here when this patch is released!

Super happy to hear that.
Please keep us up to date