Application migrated from 7.9 to 8.1 - import command failure

Hi all,

I am moving an application from 7.9 to 8.1 and I am in the scripting part. 7.9 contains references to global scripts beginning with shared. which I update accordingly to 8.1 conventions. The application has lot of component events using the "shared" scripts in 7.9, I am transforming those to application-scoped scripts in this case while migrating.

I am getting errors on components calling those app scoped scripts (former global scripts) even while importing built-in packages (i.e. the script even does not begin execution, it is enough to reference a method from the script in the component event script to get the error on lines where the import begins):

The script begins with:

from java.util import Calendar
from java.util import Date
from calendar import monthrange
from time import gmtime, strftime
import time
import datetime
from datetime import datetime, timedelta

When I copy-paste in v8.1 these import commands to scripts editor, I get the same error as the component calling the script with those imports generates:

Java Traceback:
Traceback (most recent call last):
File "<input>", line 3, in
File "C:\Users\my.username.ignition\cache\gwserver_80\C0\pylib\calendar.py", line 9, in
import datetime
File "C:\Users\my.username.ignition\cache\gwserver_80\C0\pylib\datetime.py", line 20, in
import time as _time
java.lang.IllegalArgumentException: Cannot create PyString with non-byte value

... does anyone know how to approach this one?

Thank you

I vaguely recall seeing something like that. The Right Answer™ is to not use any of these:

from calendar import monthrange
from time import gmtime, strftime
import time
import datetime
from datetime import datetime, timedelta

Jython's date and time and calendar libraries are notoriously buggy in the java environment. Don't use them. At all.

You show java's Date and Calendar imports. Use those. Consider also the various java classes from java.time. Those are particularly useful for managing time zones in Perspective.

Side note:

Why? The conversion process to v8+ quite carefully sets things up so shared.* still works correctly, allowing you to migrate to new conventions when you want to, or want to use some inheritance feature, not because you immediately need to. Save this part for later.

3 Likes

If that's truly the stacktrace, then this is 100% a Jython stdlib bug. Probably because the Jython stdlib you have is from whatever version of Ignition you originally started with, rather than whatever is current for Jython 2.7 in 8.X. You can stand up a new Ignition instance from scratch and compare the user-lib/pylib folder to the files in your gateway backup, and bring in the newer files, which will likely patch over this bug.

Or, to Phil's point...just avoid the Jython standard library. Pretty much entirely. Java imports are guaranteed to be updated, because it's the runtime we're on. Python stuff can't be safely upgraded for you, so you have to do it manually.

3 Likes

Hello both, thank you for your valuable answers, appreciated. This decides my next steps.

To Phil's 7.9 to 8.1 migration point - good point sir, for majority of the projects I will use the path you have outlined, however for this one it's not possible due to reasons I don't want to bother you with.

Nevertheless, both comments have been of a tremendous value for me.