You may have not noticed the following issue (good) but I think it's good to know it in case you face it and don't want to waste a long time troubleshooting :-)
Import and Event/Custom scripts are currently using different versions of Jython.
Before we start with details I'm sure you have noticed that FDMEE currently uses Jython 2.5.1. If not, just set log level to 5, run any FDMEE workflow, and have a look to the FDMEE process log:
So how did I come across this issue? I was trying to use a nice Python module called csv which provides functionality to easily manage csv files. It can be very useful to work with text files having quotes, delimiters, amounts having field delimiter as thousands/decimal separator, etc. I had some issues with the amount's thousands separator as you can see in the following example:
Basically split function ignores that fields are quoted as comma delimiter for numbers is also the split delimiter.
I'm not going to talk about the csv module today but I encourage you to have a look and play with it. This module was introduced in Python 2.3 as you can see in the following documentation:
This is a good starting point.
Import Script using the csv module
When you use a module you have to import it. In my dummy import script, I imported the csv module as follows:
Then executed my DLR and got this ugly message saying that the module didn't exist! I had tested before from my IDE using Jython 2.5.1 so it was quite weird.
In the image below you can see how execution from Notepad++ succeeded:
Custom/Event Script using the csv module
Was the error due to FDMEE not being able to access the module? I wasn't sure so I created a dummy custom script to confirm it:
When I executed the script I could see my data line was successfully parsed and I could see the amount as expected:
Ok, so it works from custom script (I also tested from event script) but it doesn't from import scripts. Troubleshooting time!
I tried many different debug code to show Jython details in order to see if there were any issues with visibility of modules. Finally, one line of my debug code threw some lights...
If we add the following lines to both import and custom/event script we will get the Jython version used by each script:
import sys
fdmAPI.logDebug("Jython Version: %s" % str(sys.version_info))
Now it's just a matter of having a look to the FDMEE process log:
Jython Version for Custom/Event script
Jython Version for Import script
So here we have it! Import scripts use Jython 2.2.1 while Event/Custom scripts use Jython 2.5.1.
That means we cannot use the csv module from Import scripts as it was introduced in version 2.3. This was the reason our import script raised the exception we found.
To me it's no the fact they use different versions but not sharing same Jython space. Why? You cannot easily shared variables between Event and Import scripts as we could do in FDM Classic with PVarTemp variables. There are some approaches to do it but they are not straight forward as sharing variables between Event scripts for instance.
BTW as we have been talking about the csv module, I have been using it in different custom scripts to massively load FDM Classic artifacts into FDMEE:
I don't know if this issue will be solved in next patch PSU520 or 11.1.2.4 but it will be so no need to worry about it. It was just a good occasion to show some troubleshooting and Python modules.
Regards!
Quick Update
I got some question in post http://akafdmee.blogspot.com/2013/10/writing-and-testing-pythonjython.html
regarding the import of datetime module. Here you have another example of a module not available in 2.5 (https://docs.python.org/2/library/datetime.html)
Quick Update
I got some question in post http://akafdmee.blogspot.com/2013/10/writing-and-testing-pythonjython.html
regarding the import of datetime module. Here you have another example of a module not available in 2.5 (https://docs.python.org/2/library/datetime.html)
No comments:
Post a Comment
Thanks for feedback!