-
Notifications
You must be signed in to change notification settings - Fork 121
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
Collection link points to local path #838
Comments
I experienced the same issue playing around with the qgis stac browser plugin. It only happens when the root catalog / landing page is served at the root, for example |
Isn't this solved by saving Collections with E.g. we generate a lot of self contained Collections for stactools-packages examples: |
That is likely the case, but if I load a Collection from disk and create an Item for it, it's a bit weird that I have to set something in the Collection to get a relative link in the item, right? Can I specify the catalog type when loading from disk? Otherwise, I assume that if I save the Collection after the Item, the Item is not updated accordingly, right? I still have to verify, but I think that's what I did back then (i.e. load collection from disk -> create item -> save item -> not sure whether I saved the collection again, likely not). So maybe what's missing is a way to specify the catalog type when calling Collection.from_file()? @gadomski |
Yup, you're right -- reading a catalog with relative hrefs products pystac objects with absolute self hrefs: #972. I've opened that draft PR to demonstrate the problem and will use it to make a fix. |
Thanks. Just for reference, this is where it occurred to me: https://github.com/stactools-packages/noaa-mrms-qpe/blob/main/src/stactools/noaa_mrms_qpe/commands.py#L135 |
@m-mohr circling back to this one, I'm now unsure of what the issue is. I implemented your workflow, as described in #838 (comment), here: 247d27c. That test doesn't fail -- the item is saved with relative hrefs. I must be misunderstanding your scenario -- can you help clarify? Thanks. |
@gadomski I'm not 100% sure about the test (not sure what |
Yes, the prebuilt catalog is created by reading https://github.com/stac-utils/pystac/blob/ba073056e420a99bab0e5287687246fa4ab8f320/tests/data-files/catalogs/test-case-1/catalog.json.
Hm, then how did you add the |
I haven't added the item link to the collection to keep the collection clean as I assumed it would not be relevant if you ingest into MS PC and generate links dynamically anyway. See https://github.com/stactools-packages/noaa-mrms-qpe/blob/main/src/stactools/noaa_mrms_qpe/commands.py#L135 for details. |
I think I've figured out the issue, thanks for your patience and your iterations. You're bumping into some complexities around how pystac resolves link hrefs. Specifically, link resolution is absolute by default, and only uses relative hrefs if the link's owner has a root and the root is a "relative" Catalog type: Lines 169 to 185 in 8db9afb
I'm not sure if this a bug per se; it might just a complex and relatively undocumented system. @m-mohr what would be your preferred resolution? ExamplesThis test fails: def test_collection_link_is_relative(item: Item, collection: Collection) -> None:
collection.set_self_href("http://pystac.test/collection.json")
item.set_self_href("http://pystac.test/item.json")
item.set_collection(collection)
link = item.get_single_link("collection")
assert link
assert link.href == "./collection.json" # link.href is "http://pystac.test/collection.json" In order to get your desired behavior (relative collection href), you need to make a couple changes: def test_collection_link_is_relative(item: Item, collection: Collection) -> None:
collection.set_self_href("http://pystac.test/collection.json")
collection.catalog_type = CatalogType.SELF_CONTAINED # ensure the collection is a "relative" root (self contained or relative published)
item.set_self_href("http://pystac.test/item.json")
item.set_collection(collection)
item.set_root(collection) # the item needs a root to enable relative hrefs
link = item.get_single_link("collection")
assert link
assert link.href == "./collection.json" |
Moving this to the 1.8 milestone so it doesn't hold up 1.7. |
While I see a lot of code that normalizes asset hrefs and make them relative whenever required, it seems I always end up with a local file path for the collection link. I think the collection link should be normalized as well and ideally be relative to the self link.
The text was updated successfully, but these errors were encountered: