Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing conversion if author name is not set #76

Merged
merged 5 commits into from
Mar 26, 2024

Conversation

dnlbauer
Copy link
Contributor

@dnlbauer dnlbauer commented Mar 26, 2024

When running cwltool --provenance with a set orcid, but not a full name (i.e. cwltool --provenance prov --orcid ORCID ... vs cwltool --provenance prov --orcid ORCID --full-name "Max Mustermann" ...), the resulting metadata in the CWLProv will have an ORCID set, but no corresponding name property. Trying to convert such an object to an ro-crate fails:

❯ runcrate convert prov_no_name -o ro
Traceback (most recent call last):
  File "/home/dbauer/.local/bin/runcrate", line 8, in <module>
    sys.exit(cli())
  File "/home/dbauer/.local/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/dbauer/.local/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/dbauer/.local/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/dbauer/.local/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/dbauer/.local/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/dbauer/.local/lib/python3.10/site-packages/runcrate/cli.py", line 72, in convert
    crate.write(output)
  File "/home/dbauer/.local/lib/python3.10/site-packages/rocrate/rocrate.py", line 453, in write
    writable_entity.write(base_path)
  File "/home/dbauer/.local/lib/python3.10/site-packages/rocrate/model/metadata.py", line 80, in write
    json.dump(as_jsonld, outfile, indent=4, sort_keys=True)
  File "/usr/lib/python3.10/json/__init__.py", line 179, in dump
    for chunk in iterable:
  File "/usr/lib/python3.10/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib/python3.10/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.10/json/encoder.py", line 325, in _iterencode_list
    yield from chunks
  File "/usr/lib/python3.10/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.10/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/usr/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type QualifiedName is not JSON serializable

The reason is that the type of the label property from the prov library depends on whether the name is set or not (it is either the full name as string, or a QualifiedName Object of format orcid:<id>.

This PR fixes the exception by only writing the agent's name if the name was actually set in the CWLProv and omitting it if it is not set.

Copy link

codecov bot commented Mar 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.72%. Comparing base (9d83b8b) to head (81c4feb).
Report is 3 commits behind head on main.

❗ Current head 81c4feb differs from pull request most recent head cbfd4c0. Consider uploading reports for the commit cbfd4c0 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #76      +/-   ##
==========================================
+ Coverage   97.69%   97.72%   +0.03%     
==========================================
  Files          13       13              
  Lines        2039     2066      +27     
==========================================
+ Hits         1992     2019      +27     
  Misses         47       47              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@simleo
Copy link
Collaborator

simleo commented Mar 26, 2024

Thanks for this fix @dnlbauer ! Before I merge, I need you to add your copyright line to the files you've modified, i.e. src/runcrate/convert.py and tests/test_cli.py. The header of the latter, for instance, should look like:

# Copyright 2022-2024 CRS4.
# Copyright 2024 <Daniel's company>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# ...

Please also double check that the changes I've made to CITATION.cff are correct.

@dnlbauer
Copy link
Contributor Author

@simleo thanks for the fast response on this PR. I updated the copyright accordingly. The cff looks good to me 👍

@simleo simleo merged commit c30f31c into ResearchObject:main Mar 26, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants