4.22 Release - Python Script Issues / Fixes
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.