Publish Manager nuke-writenodes error - is not json serializable

Hi everyone!
I am trying to write some scripts to publish sessions in the render farm but I am having some troubles to save a publish tree to a file inside nuke. When I run the publish manager everythng works until I try to save the tree to a file. It seems that “sg_writenode_app” and “sg_writenode” properties of the nuke-writenode item are not serializable. Any suggestios? Thank you in advance.
This is the error:

“C:\Program Files\Nuke12.2v3\python27.zip\json\encoder.py”, line 184, in default

TypeError: <Sgtk App 0x1e2faa16ef0: tk-nuke-writenode, engine: <Sgtk Engine 0x1e2dbfa5978: tk-nuke, env: shot_step>> is not JSON serializable

What you are trying to serialize is the writenode python object. That is not serializable - it has references to the engine, context, neither of which is serializable.

This is not the publish tree though. Show us some code or explain in more detail what you want to achieve.

This is the code:

import sgtk

engine = sgtk.platform.current_engine()

get the publish app instance from the engine’s list of configured apps

publish_app = engine.apps.get(“tk-multi-publish2”)

ensure we have the publisher instance.

if not publish_app:

raise Exception("The publisher is not configured for this context.")

create a new publish manager instance

manager = publish_app.create_publish_manager()

now we can run the collector that is configured for this context

manager.collect_session()

manager.tree.save_file(pathToFile.txt)

#print (“Publish tree saved”)

I am trying to collect the session inside nuke and write it out to a file so I can later use it in the render farm to publish in a non gui session. It fails if there is a tk-nuke-writenode to publish. “sg_writenode_app” and “sg_writenode” properties are part of the default configuration for nuke collector.
This code is taken from the documentation for the publish manager.
Is it posible to keep those properties or should I remove then before trying to write the publish tree?

I am not familiar with this workflow, will dig deeper into the code later on.

Thank you very much!