cancel
Showing results for 
Search instead for 
Did you mean: 

4.22 Release - Python Script Issues / Fixes

del
Contributor III

In addition to the Known Issues in the 4.22 Release Notes, I want to raise some awareness to a couple of other issues and fixes that I’ve experienced with the Python Script after the 4.22 upgrade - (with the intent of helping anyone else that may be impacted).

Disclaimer: I’m no Python expert, especially 5 or 6 years ago when I wrote the originals (I had never used Python before), so I might have had better options in the beginning. But if you find yourself in a similar situation, hopefully this will help. I’m also open to any alternatives from those who are Python experts.

Issue 1 – zlib.compress():
I am using the zlib library to compress JSON being pulled from the SnapLogic APIs, to back up pipelines, accounts, etc. to a database. With the following Python code, at least one particular pipeline, it was trying to compress, began throwing an “ascii … ordinal not in range(128)” error.

Original:

in_doc["json"] = zlib.compress(in_doc["json"])

Fix:

in_doc["json"] = zlib.compress(in_doc["json"].encode("utf-8"))

Issue 2 – {dictionary}.values().toArray()[i]:
Prior to 4.22, if I wanted to subscript a {dictionary}.values() method, I had to append the toArray() method to values(). Otherwise, I would get a “Failure: ‘java.util.LinkedHashMap$LinkedValues’ object is unsubscriptable” error. After 4.22, toArray() is not valid, returning “Failure: ‘list’ object has no attribute ‘toArray’”. However, the requirement for toArray() is no longer necessary for the subscript.

Original:

sLine = data.values().toArray()[0]

Fix:

sLine = data.values()[0]


A funny side-note: The “Breaking change” that the Release Notes have highlighted with a red border is actually a fix for another issue I previously had.

1 REPLY 1

ptaylor
Employee
Employee

Thank you. This is a helpful share. Our Jython engine upgrade in the 4.22 release definitely had a compatibility impact. This is rather unavoidable due to the nature of the changes in Jython 2.7 itself. That Jython release prioritized usability and interoperability with Java over backward compatibility. One of the Jython developers admitted as much here: Message 10171 - Jython tracker. As he said, “I assure you that this is not the only backwards incompatible change in the latest Jython.” The various breaking changes in Jython 2.7 are probably mentioned in various tickets and Stackoverflow posts, but we can find no comprehensive list of such incompatibilities in release notes or the like. Your post here is a useful addendum to our documentation on this issue. I’ll suggest to our Doc team that they consider integrating this content into our documentation.