Skip to content

Cannot load CWL definition directly with Python objects using Factory class #1903

@fmigneault

Description

@fmigneault

Expected Behavior

from cwltool.factory import Factory
import json 
with open("/tmp/base.json", mode="r", encoding="utf-8") as f:
    cwl = json.load(f)
cwl
{'cwlVersion': 'v1.2', 'class': 'CommandLineTool', 'baseCommand': 'echo', 'inputs': {'input': {'type': 'int'}}, 'outputs': {'output': 'stdout'}}

#----------
tool = Factory().make("/tmp/base.json")
Resolved '/tmp/base.json' to 'file:///tmp/base.json'

tool(input=1)
[job base.json] /tmp/2ntkyyif$ echo > /tmp/2ntkyyif/054dc6206b72fb355c36f9ab1c37be5233d88d70
[job base.json] completed success
{'output': {'location': 'file:///tmp/2ntkyyif/054dc6206b72fb355c36f9ab1c37be5233d88d70', 'basename': '054dc6206b72fb355c36f9ab1c37be5233d88d70', 'nameroot': '054dc6206b72fb355c36f9ab1c37be5233d88d70', 'nameext': '', 'class': 'File', 'checksum': 'sha1$adc83b19e793491b1c6ea0fd8b46cd9f32e592fc', 'size': 1, 'http://commonwl.org/cwltool#generation': 0}}

#----------
tool = Factory().make(cwl)
Traceback (most recent call last):
  File "/opt/pycharm-2023.2/plugins/python/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/cwltool/factory.py", line 67, in make
    load = load_tool.load_tool(cwl, self.loading_context)
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/cwltool/load_tool.py", line 605, in load_tool
    loadingContext, uri = resolve_and_validate_document(
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/cwltool/load_tool.py", line 519, in resolve_and_validate_document
    uri = processobj["id"]
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/ruamel/yaml/comments.py", line 927, in __getitem__
    return ordereddict.__getitem__(self, key)
KeyError: 'id'

#-------- 
cwl["id"] = "file:///tmp/base.json"
tool = Factory().make(cwl)

tool(input=1)
[job base.json_2] /tmp/vn0i5ukp$ echo > /tmp/vn0i5ukp/054dc6206b72fb355c36f9ab1c37be5233d88d70
[job base.json_2] completed success
{'output': {'location': 'file:///tmp/vn0i5ukp/054dc6206b72fb355c36f9ab1c37be5233d88d70', 'basename': '054dc6206b72fb355c36f9ab1c37be5233d88d70', 'nameroot': '054dc6206b72fb355c36f9ab1c37be5233d88d70', 'nameext': '', 'class': 'File', 'checksum': 'sha1$adc83b19e793491b1c6ea0fd8b46cd9f32e592fc', 'size': 1, 'http://commonwl.org/cwltool#generation': 0}}

Actual Behavior

When the id field is missing and the CWL is provided directly as Python objects, the following error is raised:

KeyError: processobj["id"]

However, the code seems to attempt adding a temporary id (in the form _:<UUID> beforehand) to work around the "missing" document reference when the contents are provided directly. Therefore, the above processobj reference seems invalid.

Workflow Code

see above

Full Traceback

Traceback (most recent call last):
  File "/opt/pycharm-2023.2/plugins/python/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/cwltool/factory.py", line 67, in make
    load = load_tool.load_tool(cwl, self.loading_context)
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/cwltool/load_tool.py", line 605, in load_tool
    loadingContext, uri = resolve_and_validate_document(
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/cwltool/load_tool.py", line 519, in resolve_and_validate_document
    uri = processobj["id"]
  File "/home/francis/dev/conda/envs/weaver/lib/python3.10/site-packages/ruamel/yaml/comments.py", line 927, in __getitem__
    return ordereddict.__getitem__(self, key)
KeyError: 'id'

Your Environment

  • cwltool version: 3.1.20230906142556

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