Chaffelson / nipyapi

A convenient Python wrapper for Apache NiFi
Other
243 stars 76 forks source link

NiPyAPI import_flow_version issue #345

Closed j7smith closed 2 months ago

j7smith commented 3 months ago

We are in the process of migrating/upgrading from Python3.7 to Python3.9. When executing the following command: nipyapi.versioning.import_flow_version

I get the error: "safe_load()" has been removed, use...

Here is the code block:

try:
   # import the encoded nifi flow that was from the file and load it into the target environment registry
   print(f'JTS #03')
   nipyapi.versioning.import_flow_version(registry_bucket_id, encoded_flow=registryFlow_input, flow_name=flow_name)
   print(f'JTS #04')
except Exception as error:
   print(f'REGISTRY IMPORT EXCEPTION: {error}')
   traceback.print_exc()

Here is the trace:

JTS #03
REGISTRY IMPORT EXCEPTION: 
"safe_load()" has been removed, use

  yaml = YAML(typ='safe', pure=True)
  yaml.load(...)

instead of file "/usr/local/lib/python3.9/site-packages/nipyapi/utils.py", line 101

    loaded_obj = ruamel.yaml.safe_load(obj)

Traceback (most recent call last):
  File "/var/opt/bamboo/bars/jts-projects/nifideploy/nifiscripts2/nifiTrainingDeploymentRegistryTest2Lint-vlad-02.py", line 2101, in processDeploymentLocal10
    nipyapi.versioning.import_flow_version(registry_bucket_id, encoded_flow=registryFlow_input, flow_name=flow_name)
  File "/usr/local/lib/python3.9/site-packages/nipyapi/versioning.py", line 651, in import_flow_version
    imported_flow = nipyapi.utils.load(
  File "/usr/local/lib/python3.9/site-packages/nipyapi/utils.py", line 101, in load
    loaded_obj = ruamel.yaml.safe_load(obj)
  File "/home/bamboo/.local/lib/python3.9/site-packages/ruamel/yaml/main.py", line 1105, in safe_load
    error_deprecation('safe_load', 'load', arg="typ='safe', pure=True")
  File "/home/bamboo/.local/lib/python3.9/site-packages/ruamel/yaml/main.py", line 1037, in error_deprecation
    raise AttributeError(s)
AttributeError: 
"safe_load()" has been removed, use

  yaml = YAML(typ='safe', pure=True)
  yaml.load(...)

instead of file "/usr/local/lib/python3.9/site-packages/nipyapi/utils.py", line 101

    loaded_obj = ruamel.yaml.safe_load(obj)

When executing the code using Python3.7 there are no issues but once I try to execute the code under Python3.9 we started seeing the above issue.

This issue is pretty critical since Python3.7 is tagged to be EOL and our organization has made the decision to remove previous version from the system. Python3.9 will be designated the minimum codebase for all NiFi related projects moving forward.

Hope this helps. Please let me know if you need additional info

Chaffelson commented 3 months ago

Can you check what version of ruamel.yaml has been installed by your deps manager? We deliberately pin <=0.18 as they deprecated these safe loading methods in 0.18+ and last I checked 0.17.x was working well.

Although I have tested with Python3.9, it may be that various libraries will force us to move forward the minimum versions once again. You may not be surprised to find that many users still use Py2 😅

Chaffelson commented 3 months ago

Found the problem. At some point I allowed ruamel.yaml to install <=0.18, rather than <0.18, and they finally deprecated the calls. I will test a fix today.

j7smith commented 3 months ago

Apologies for the delayed response. My schedule is a bit crazy so I'm playing catchup. In answer to your raumel.yaml question, I am using version 0.18.6. Shall I rollback the version of raulmel.yaml or pull #346?

Chaffelson commented 3 months ago

@j7smith you can either pull that branch, or probably easier to just run pip install --upgrade "ruamel.yaml<0.18" in the virtualenv you are running NiPy in.