Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

NiFi ExecuteScript - Able to add attributes to created FlowFiles?

avatar
New Contributor

Hi all, I am passing a FlowFile with several custom attributes to my ExecuteScript processor (running python). I want the ExecuteScript to create two new FlowFiles, each having their own set of attributes (the values are to be retrieved from the input FlowFile). Problem is, I am unable to add any attributes to the two new flowfiles and it throws the error "org.apache.nifi.controller.repository.StandardFlow" object has no attribute "putAttribute". 

 

flowFile = session.get()
if flowFile != None:
    ...
    destFlowFile = session.create(flowFile)
    # doesn't work
    destFlowFile.putAttribute(destFlowFile, "logMsg", "Testing Msg")
    destFlowFile.putAllAttributes(destFlowFile, backupAttributes)

 

 I've followed the examples listed in this guide https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-1/ta-p/248922, hence I wasn't expecting this to not work. Is it just not possible to add attributes to created FlowFiles and if so, are there any alternative methods? Thank you!

1 ACCEPTED SOLUTION

avatar
Master Guru

The operation to add an attribute to a FlowFile is on the ProcessSession object not the FlowFile itself (so the session can keep track of changes).  Try the following instead:

 

session.putAttribute(destFlowFile, , "logMsg", "Testing Msg")

session.putAllAttributes(destFlowFile, backupAttributes)

View solution in original post

2 REPLIES 2

avatar
Master Guru

The operation to add an attribute to a FlowFile is on the ProcessSession object not the FlowFile itself (so the session can keep track of changes).  Try the following instead:

 

session.putAttribute(destFlowFile, , "logMsg", "Testing Msg")

session.putAllAttributes(destFlowFile, backupAttributes)

avatar
New Contributor

Ah I'm so careless, thanks for pointing that out!