Skip to content

Issues when exporting workflows #3230

@matteomancini

Description

@matteomancini

Summary

During the last OHBM Hackathon, I found two bugs while working on my project: these arise when one tries to export a given workflow using the respective export() method (for example assembled combining multiple ones at runtime) to a .py file. I managed to fix them following @satra advices on Mattermost, and I will open a pull request shortly.

Actual behavior

  1. Any node defined with the fields parameter, e.g.:
inputnode = pe.Node(
   interface=util.IdentityInterface(fields=['dwi','bvecs','bvals']),
   name="inputnode")

will be misrepresented when the workflow is exported using wf.export('wf.py'), e.g.:

workflow_inputnode = Node(IdentityInterface(mandatory_inputs=True), name="workflow_inputnode")

This issue can be fixed removing the following line (which skips the fields parameter):

args = args[1:]

  1. Once the previous issue is fixed, the generated Python file cannot be executed because of the following error:
NameError: name \'stream\' is not defined\n'

This is caused by these lines:

filled_args.append(
"%s=%s" % (arg, getattr(node.interface, "_%s" % arg))
)

To correctly handle strings and lists as parameters, @satra suggested to add an if statement:

                     argval = getattr(node.interface, "_%s" % arg)
                     if isinstance(argval, str):
                         filled_args.append(
                             "%s='%s'" % (arg, argval)
                         )
                     else:
                         filled_args.append(
                             "%s=%s" % (arg, argval)
                         )

Expected behavior

It is expected that the export() method would be able to handle the fields parameter.

How to replicate the behavior

Any workflow containing an IdentityInterface node with the fields parameter will replicate the issues.

Script/Workflow details

NA

Platform details:

NA

Execution environment

Choose one

  • Container NA
  • My python environment inside container NA
  • My python environment outside container 3.7.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions