Skip to content

Self HREFs are not always absolute #571

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

Closed
gadomski opened this issue Jul 20, 2021 · 1 comment
Closed

Self HREFs are not always absolute #571

gadomski opened this issue Jul 20, 2021 · 1 comment

Comments

@gadomski
Copy link
Member

In the documentation for STACObject.get_self_href, it states that the returned HREF will be absolute:

def get_self_href(self) -> Optional[str]:
"""Gets the absolute HREF that is represented by the ``rel == 'self'``
:class:`~pystac.Link`.
Returns:
str or None: The absolute HREF of this object, or ``None`` if
there is no self link defined.
Note:
A self link can exist for objects, even if the link is not read or
written to the JSON-serialized version of the object. Any object
read from :func:`STACObject.from_file <pystac.STACObject.from_file>` will
have the HREF the file was read from set as it's self HREF. All self
links have absolute (as opposed to relative) HREFs.
"""
self_link = self.get_single_link(pystac.RelType.SELF)
if self_link and self_link.has_target_href():
return self_link.get_target_str()
else:
return None

However, no work is done to ensure that the self href is absolute, as demonstrated by this failing test:

def test_relative_self_href(self) -> None:
    self.item.add_link(pystac.Link("self", "a/relative/path/item.json"))
    # this fails
    self.assertEqual(
           self.item.get_self_href(), os.path.abspath("a/relative/path/item.json")
    )

This is true for objects read via, e.g. pystac.read_file as well. Should the returned self HREF be resolved to an absolute HREF as best as possible, or should we just return None?

@lossyrob
Copy link
Member

Fixed by #574

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

No branches or pull requests

2 participants