common-workflow-language / common-workflow-language/cwltool

CWLViewer error when subworkflows are used

Open
#1,381 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
376
Forks
255
Avg merge
2d 7h
Merged PRs (30d)
12

Description

When running the following:
```
cwltool --debug --print-dot workflow-with-nested-subworkflow.cwl | dot -Tpng -o foo.png
```

I get the following error:

```
ERROR Tool definition failed initialization:
Cannot identify root workflow! Notice that only Workflows can be visualized
Traceback (most recent call last):
File "/home/alexiswl/anaconda3/envs/cwl/lib/python3.8/site-packages/cwltool/main.py", line 1005, in main
printdot(tool, loadingContext.loader.ctx, stdout)
File "/home/alexiswl/anaconda3/envs/cwl/lib/python3.8/site-packages/cwltool/cwlrdf.py", line 198, in printdot
cwl_viewer = CWLViewer(printrdf(wf, ctx, "n3")) # type: CWLViewer
File "/home/alexiswl/anaconda3/envs/cwl/lib/python3.8/site-packages/cwltool/cwlviewer.py", line 28, in __init__
self._root_graph_uri = self._get_root_graph_uri() # type: str
File "/home/alexiswl/anaconda3/envs/cwl/lib/python3.8/site-packages/cwltool/cwlviewer.py", line 146, in _get_root_graph_uri
raise RuntimeError(
RuntimeError: Cannot identify root workflow! Notice that only Workflows can be visualized
```

I found that a workaround of this is:

Step 1: Comment out the following lines under `_get_root_graph_uri`

```python
if len(root) != 1:
print(root)
raise RuntimeError(
"Cannot identify root workflow! Notice that only Workflows can be visualized"
)
```

Step 2:

Collect the last workflow instead under `_get_root_graph_uri`

```python
workflow = root[-1]["workflow"]

return workflow
```

I've tried this half-a-dozen times now with no issue - can I assume that the last item of `root` is always the highest level workflow.
Is this an oversight? Or is there a reason that we cannot just return the last element of the `root` array?

For reference this is the `_get_root_graph_uri` function
```python
def _get_root_graph_uri(self) -> rdflib.URIRef:
with open(self._get_root_query_path) as f:
get_root_query = f.read()
root = list(
self._rdf_graph.query(
get_root_query,
)
)
if len(root) != 1:
print(root)
raise RuntimeError(
"Cannot identify root workflow! Notice that only Workflows can be visualized"
)

workflow = root[-1]["workflow"] # type: rdflib.URIRef
return workflow
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.