Skip to content

Commit

Permalink
fix: remove duplicate self links on items
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Apr 24, 2023
1 parent 81587b1 commit 09a806f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 0 additions & 5 deletions pystac/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,9 @@ def from_dict(
assets={k: Asset.from_dict(v) for k, v in assets.items()},
)

has_self_link = False
for link in links:
has_self_link |= link["rel"] == pystac.RelType.SELF
item.add_link(Link.from_dict(link))

if not has_self_link and href is not None:
item.add_link(Link.self_href(href))

if root:
item.set_root(root)

Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ def test_case_1_catalog() -> Catalog:
def projection_landsat8_item() -> Item:
path = TestCases.get_path("data-files/projection/example-landsat8.json")
return Item.from_file(path)


@pytest.fixture
def sample_item() -> Item:
return Item.from_file(TestCases.get_path("data-files/item/sample-item.json"))
5 changes: 5 additions & 0 deletions tests/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,8 @@ def test_geo_interface() -> None:
item.to_dict(include_self_link=False, transform_hrefs=False)
== item.__geo_interface__
)


def test_duplicate_self_links(sample_item: pystac.Item) -> None:
# https://github.com/stac-utils/pystac/issues/1102
assert len(sample_item.get_links(rel="self")) == 1

0 comments on commit 09a806f

Please sign in to comment.