A JSON SQL query watching a value is constantly firing even though the value has not changed

I have a non-react custom control (ccPrintInvoice) in a module (PrintInvoice). I trigger a function inside of ccPrintInvoice which generates a PDF. Since I cannot call the function directly, I am subscribing to the model to watch any changes.

When it sees model.begin go high, it runs the function and immediately sets model.begin low so it does not trigger again. model.begin is linked to a module input called start and that is linked to the temp var StartInvoice back in the app.

I am also setting model.working high while the PDF is being worked on. When done, the function sets model.url to the PDF's url.

I am using model as the output to the module.

Back on the app, I watch model.working using a JSON with SQL query. It then triggers a JS that sets StartInvoice back to false.

Well, the JSON with SQL query fires constantly even though the watched value has not changed. Also the model subscription continuously fires. If I disable the query, the model subscription also calms down.

I know this is kind involved.

Here is the workflow and screencaps below.

In app, set startInvoice true. In module this is received by the start input which is tied to model.begin in the CC (custom component.) The model subscription fires due to the change and sees that model.begin is true. model.begin set to false. model.working set to true and PDF builds. model.working set to false, model.url set. In the app JSON query triggers when model.working changes and sets startInvoice to false. This triggers the model subscription in the CC which should ignores it as false.

Module with CC:

App with my query:

My guess as to what is happening. Setting startInvoice to false of course ends up setting the model.begin to false which triggers the model subscription. The model subscription checks model and something about that resets the model which then propagates back up and triggers the query watching the model which fires again. Rinse, lather, repeat.

Hey @bradlymathews!

Great question, it sounds like this could be a dependency loop.

In your app, startInvoice is set to true, which triggers model.begin to change which then changes model.working to true. model.working triggers the resetStartInvoice query, which I believe updates model.begin, triggering model.working and so on.

It's hard to tell without seeing more of your app but let me know if this seems correct here?

Yeah, that is about right. And a dependency loop was my first suspect. But model.working stays false after that so I would expect that the query would not trigger as the value does not change.

"When inputs change" is more accurate described as "When inputs are re-evaluated". We've discussed changing the behavior to compare previous values, but it would affect existing workflows and needs to be carefully considered.

If an input is to a query is recalculated, it will cause the query to trigger again even if the value is equal before and after

1 Like

That is what I suspected. Ok I will have to get a little smarter on this part of my system. :brain: :brain:

I have been experiencing this as well. I have a module with a module query input. I have connected this to a JS query in an app. The JS query just increments a temporary state. The temporary state is fed into a different module that is watching the input with a JSON query to then initiate other in module events. While the app sits doing nothing, I see this module query constantly and seemingly randomly getting triggered. It feels like a circuit board that has a logic pin left floating. Sometimes while in edit mode as I move my mouse around the canvas, it seems almost like the query gets triggered more.

Hey Shawn! Happy to check this one out, definitely shouldn't be happening. What is the name of the app + module in question? :slight_smile: