Community Edition 2019.2.0 bug (Remove Unused Variables)

studio
bug
#1

Hi, when i pressed “remove unused variables” in 2019.2.0 CE it wiped all variables from entire project, used and unused alike.

P.S. not sure if this is correct category

#2

Hi @Kelebrim

Could you post a sample project or a video of this happening? I’ve just tested it and it works for me on 2019.2

Are you sure that the variables were referenced in the project?

1 Like
#3

Hi @loginerror
Long story short… in a flowchart i connected start node to a comment that was on top of next sequence.
Untitled

Sorry for false alarm and thank you for fast response.

1 Like
#4

I wouldn’t call them unreferenced, they’re more unreachable (there’s a difference).
There’s still something buggy about it, though…

Repro:

  1. Create a workflow like this.
    image
  • ‘reachable1’ and ‘reachable2’ are standard
  • ‘unreachable1’ is unconnected, like in your example above
  • ‘unreachable2’ is connected, but in reality unreachable (decision is hardcoded to ‘True’ literal, which in VS would be marked as unreachable like in screen below, but for workflows it needs to evaluate it at runtime, so here it’s technically part of a valid code path).
  1. Make a copy (there are a couple of scenarios to go through).

  2. On a fresh copy:

  • Open the xaml
  • Press RemoveUnreferencedVariables
  • Observe that ‘unreachable1’ variable is removed
    Comment: this is currently the “expected” behaviour, but the naming is a little misleading, since unreferenced is different than unreachable
  1. On a fresh copy:
  • Open the xaml
  • Set Flowcharts “ValidateUnconnectedNodes” value to True
  • Set Flowcharts “ValidateUnconnectedNodes” value back to False
  • Press RemoveUnreferencedVariables
  • Observe that ‘unreachable1’ variable is NOT removed and no changes to the workflow will make it so
  • Close the xaml and reopen it
  • Press RemoveUnreferencedVariables
  • Observe that ‘unreachable1’ variable is removed
    Comment: so it seems that ValidateUnconnectedNodes, even just by being toggled back and forth, modifies the cached xaml in a way that the ‘unreachable1’ is now visible
  1. On a fresh copy:
  • Open the xaml
  • Connect the assign with ‘unreachable1’ to one of the end nodes
  • Press RemoveUnreferencedVariables
  • Observe that ‘unreachable1’ variable is not removed
  • Disconnect the assign with ‘unreachable1’
  • Press RemoveUnreferencedVariables
  • Observe that ‘unreachable1’ variable is NOT removed
    Comment: so it seems that if at any point when the workflow is opened, a variable in a flowchart that has been a part of an execution path is still there (i.e. there is only a difference in flow transitions), it’s treated as referenced

So to sum it up so far:
RemoveUnreferencedVariables, when acting on a Flowchart that has ValidateUnconnectedNodes = False, treats variables in fully unreachable (disconnected) nodes as unreferenced, but due to some sort of caching, if a variable at any point when the workflow was open was part of a valid path, it’s treated as referenced until workflow is fully reloaded.

Interaction with CommentOut:
Same happens for variables that are only referenced within a CommentOut scope - they’re treated as Unreferenced as well from the perspective of RemoveUnreferencedVariables.

Full summary:
RemoveUnreferencedVariables works reliably with Flowcharts only if no flow changes have been made from the moment they’re opened.
“Unreferenced” should be treated as “will not be executed under any theoretical processing path regardless of branching evaluations”, so it more matches a “conservatively unreachable” definition than unreferenced.

Sidenote:
There seems to be imprecise information in the documentation as well:

You can also remove all the variables that are not used in your currently opened project:

  1. On the Design ribbon tab, in the Variables group, select Remove Unused Variables . Note that the Variables panel only contains the variables used in your automation.

This doesn’t seem 100% correct, as it will remove them only from the currently active xaml, not the whole project. Minor, but still safer actually.

4 Likes
#5

This is some impressive analysis work. Hats off! We’ll log a bug against this action based on this. Remove Unused should equal Remove Unreferenced. In my opinion, based on your analysis, all the above cases were cases where no variable should have been removed, since they are, in truth, still referenced, even if unreachable. Click “Like” if this makes sense.

3 Likes
closed #6

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.