Chaffelson / nipyapi

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

AssertionError when creating connections for dynamic relationship names #303

Closed casejohnsondeloitte closed 2 years ago

casejohnsondeloitte commented 2 years ago

Description

nipyapi.canvas.create_connection() fails to create a connection from the RouteOnAttribute processor for a dynamic relationship name.

What I Did

In the NiFi UI, I've created and connected a HandleHttpRequest processor, a RouteOnAttribute processor, and a LogAttribute processor. I am adding a custom property to RouteOnAttribute using nipyapi.canvas.update_processor():

image

This creates a new connectable relationship on the processor:

image

When calling nipyapi.canvas.create_connection() with relationships=['/sample'], I am unable to create the connection for this dynamic name with the following error:

line 880, in create_connection:
assert all(i in source_rels for i in relationships), \
AssertionError: One or more relationships [['/sample']] not in list of valid Source Relationships [['unmatched']]

Urgency

We are not in production today, but building a product for production in the range of 2-3 months.

Workaround

If the processor is retrieved from the canvas again after updating its properties, the newly retrieved object will have the correct relationships. In other words:

# get the RouteOnAttribute processor from the canvas
# update its properties to add the new connectable relationship
# get the RouteOnAttribute processor from the canvas again
# create the connection using the new relationship
casejohnsondeloitte commented 2 years ago

Just kidding, this is my own misuse of the library :) Did not notice that nipyapi.canvas.update_processor() returns a new instance of the processor.

Chaffelson commented 2 years ago

actually ideally it would helpfully inform you that you are not working with the latest revision of the processor config, that would be a small but useful improvement.