Really Odd Script Behavior


Running into some really strange behavior on one of our Ignition projects.
I have some global scripts written on a shared project that various perspective projects can execute, this is and has always been working just fine.

However, this script in particular is exhibiting some really odd behavior.

def deleteTTFiles(fileIds = [ ], processHistoryFileIds = [ ], tx = ''):

I wrote this script to allow other projects to execute it via two optional parameters, and throw an error if neither is received. When I execute the function from an external perspective project, I pass in a 'processHistoryFileIds' list. It then executes and runs a query to get the 'fileIds' that it needs internal to itself.

Without getting into function detail and specifics, I have verified through a logger that the input parameters of the executing function do not match what was verified to be passed in. It seems as though one of the input parameters of the function holds its value from its last execution, when I run it from one of the other perspective projects.

The next time i run it, with the same 'processHistoryFileIds' parameter passed in, it still has the 'fileId' value from its previous execution. The 'fileId' does not re-initialize as an empty list as the definition says it should.

Anybody know what could be happening here? Is this simply due to the fact that all parameters on the function are optional and initialize as empty lists? As opposed to having a parameter that is required?
Could this be due to the function overwriting the 'fileId' variable when it was executed without it passed in? I wouldn't think so..

FWIW, i have verified even on the shared project itself that executing it from the script console does the same thing, but I can manually clear the script console to force the function to re-initialize a parameter? I put a question mark because it makes no sense but that's whats happening

Any help would be greatly appreciated


This is a super common Python gotcha. It's a little weirder in Ignition's execution environment, but the root advice still holds.


Welp, that definitely sounds like the issue to me. It's funny, if not every other function initializes arguments to None, except this one. Thanks very much for the article. Been using ignition 5 years and somehow never ran into this.