datalad / datalad-catalog

Create a user-friendly data catalog from structured metadata
https://datalad-catalog.netlify.app
MIT License
14 stars 12 forks source link

Validate won't work without a dataset #330

Closed mslw closed 11 months ago

mslw commented 11 months ago

It looks like Validate (catalog-validate) was supposed to be called with or without the catalog argument (__call__(metadata, catalog=None). However, calling it without the argument produces an error:

>>> import json
>>> from datalad.api import catalog_validate
>>> catalog_validate(metadata=json.dumps({"type": "dataset"}))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mszczepanik/.virtualenvs/tabby/lib/python3.11/site-packages/datalad/interface/base.py", line 773, in eval_func
    return return_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mszczepanik/.virtualenvs/tabby/lib/python3.11/site-packages/datalad/interface/base.py", line 763, in return_func
    results = list(results)
              ^^^^^^^^^^^^^
  File "/home/mszczepanik/.virtualenvs/tabby/lib/python3.11/site-packages/datalad_next/patches/interface_utils.py", line 218, in _execute_command_
    for r in _process_results(
  File "/home/mszczepanik/.virtualenvs/tabby/lib/python3.11/site-packages/datalad/interface/utils.py", line 319, in _process_results
    for res in results:
  File "/home/mszczepanik/Documents/datalad-catalog/datalad_catalog/validate.py", line 112, in __call__
    path=catalog.location,
         ^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'location'

This is due to creating a result record template with:

res_kwargs = dict(
    action="catalog_validate",
    path=catalog.location,
)

and could probably be solved with path=Path.cwd() if catalog is None else catalog.location

(although what exactly the path should be is not clear to me -- part of me wants it to be the metadata path, but that won't work either because metadata can be a json string, not a path...)

jsheunis commented 11 months ago

Thanks for the issue! i agree with your thoughts, so probably best to go for cwd