Strange behavior from console.log

In an event handler I have a loop which steps through a retool table. This is done like this:

for (let i = 0; i < numvec.value; i++) {
  console.log('start row=' + i)
  vector_batch.selectRow(i);

//(more stuff happens)

What then happens is that values are pulled from the table, using vector_batch.selectedRow, to drive the rest of the process. The first step is to output another string to the console.log:

console.log('description=' + vector_batch.selectedRow.data.n_description);

Then some other logic is called (a query) which accesses this same string: vector_batch.selectedRow.data.n_description.

All this seems to work fine. With each successive iteration of the loop the logic is looking at the next row in the table and vector_batch.selectedRow.data.n_description is different on each iteration.

However...looking at the console log, the output from:

console.log('description=' + vector_batch.selectedRow.data.n_description);

is correct on the first iteration of the loop but then is stuck there, outputting the same string over and over, as if the expression evaluation has been cached. This could be explained by some (broken) optimization process that does not understand that the value:
vector_batch.selectedRow.data can be changed by
vector_batch.selectRow(i);

In the parts of the code elsewhere which access vector_batch.selectedRow.data this failure mode does not seem to appear. But it is especially unwelcome inside console.log because that is where we rely on seeing correct output to really understand what the code is doing.

Hey @Roland_Alden!

By default, variables aren't kept in sync with the app model as that causes something of a performance hit. Instead, a copy of the object is made only when the query is first run. There's a setting to change this behavior though that's discussed in this thread!

Yikes. Good to know. I suspected as much and guessed this explains the other weirdness I saw. I created a checkbox in the UI and a break check at the bottom of the loop so I could terminate the loop early if I wanted to...by ticking the checkbox. That didn't work either. :rofl: