stac-utils / pystac

Python library for working with any SpatioTemporal Asset Catalog (STAC)

Home Page:https://pystac.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Validate STAC links for single dict

m-mohr opened this issue · comments

As far as I understand, validate_all implicitly validates whether the STAC links (item, child) are valid (i.e. the href exists).
It would be great if this small feature would also be available (via a flag/parameter) in the validation for a single object/dict.

Hey @m-mohr,

Does the recursive parameter in validate_all address your issue?

For example:

import pystac

catalog_file = r"https://raw.githubusercontent.com/stac-utils/pystac/main/tests/data-files/catalogs/label_catalog-v0.8.1/catalog.json"
catalog = pystac.Catalog.from_file(catalog_file)
catalog.validate_all()
>>> 62
catalog.validate_all(recursive=False)
>>> 0

I don't think so. The question is not related to recursion, more to be able to check whether link hrefs actually exist.

I don't think so. The question is not related to recursion, more to be able to check whether link hrefs actually exist.

In Catalog.validate_all, all item and child links are checked and validated regardless of the value of recursive:

pystac/pystac/catalog.py

Lines 1058 to 1069 in 9c323c4

for child in self.get_children():
if recursive:
inner_max_items = None if max_items is None else max_items - n
n += child.validate_all(max_items=inner_max_items, recursive=True)
else:
child.validate()
for item in self.get_items():
if max_items is not None and n >= max_items:
break
item.validate()
n += 1
return n

So Catalog.validate_all(recursive=False) and Catalog.validate_all(recursive=False) will check all STAC links on the Catalog/Collection without recursing into the children and validating those links.

But the issue is about validate, not validate_all.

But the issue is about validate, not validate_all.

😕 I think we currently allow all the possible cases via validate and validate_all:

  • Catalog.validate() does not read or validate links
  • Catalog.validate_all(recursive=False) reads and validates links, but does not do the same for children
  • Catalog.validate_all(recursive=True) reads and validates links, and does the same for children

Is there another behavior that I'm missing?

Oh, I see. You were saying I should use validate_all(recursive=False) instead of validate. Will try...