Hey guys,
I'm doing a script on a container where I write on a tag with datatype dataset the result from a query to my database( this is only written once). After having that information saved on the tag, for the goal to avoid doing queries where the information is the exact same rows and columns only changing the values in some points. I did a function that can do those changes. When I write the dataset in the tag, instead of replacing the information that was held previously, it appends to what already is. Is it normal? Shouldn't it overwrite the information that was there before? I'm forced to erase the value that is on the tag before placing the information again? Any tips?
tagpath = "[AGV_Tags]LayoutDataset"
#tag read
LayoutTag = system.tag.read(tagpath).value
newLayout = Node_Layout.MapStatus_Update.Map_Update(LayoutTag, 1)
#Dataset_tag test
callback = system.tag.writeAsync(tagpath, newLayout)
event.source.getComponent('Template Canvas').templates = newLayout
We can't tell what's wrong without seeing the function that modifies the dataset...
One thing though: use system.tag.readBlocking
instead of system.tag.read
. That last one is deprecated.
Also, be mindful of what can write to that dataset tag.
Sorry to put you through this problem. The issue was inside the function I developed. Figured out today that when declaring variables as empty lists, it's better to avoid doing what I did (the mistake):
DataNode = output_data = []
Because when you some .append or .extend, even if you just place one variable, both variables will be modified. I didn't know this.
Again, sorry, and thanks anyways!
Both variables are actually the same object. You're not appending to both, you're appending to one list, that is referenced by 2 different identifiers.
If you want to create 2 DIFFERENT lists, you can do that:
foo, bar = [], []
Yeah I figured out only now. I thought I was simply declaring both variables as an empty list. If I wanted them to keep being equal, I would have to use them every step where I do modifies to one. Just like an integer variable. At least that's how I interpreted it. But now I know. Thanks again!