Skip to content

Commit 09a806f

Browse files
committed
fix: remove duplicate self links on items
1 parent 81587b1 commit 09a806f

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

pystac/item.py

-5
Original file line numberDiff line numberDiff line change
@@ -476,14 +476,9 @@ def from_dict(
476476
assets={k: Asset.from_dict(v) for k, v in assets.items()},
477477
)
478478

479-
has_self_link = False
480479
for link in links:
481-
has_self_link |= link["rel"] == pystac.RelType.SELF
482480
item.add_link(Link.from_dict(link))
483481

484-
if not has_self_link and href is not None:
485-
item.add_link(Link.self_href(href))
486-
487482
if root:
488483
item.set_root(root)
489484

tests/conftest.py

+5
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ def test_case_1_catalog() -> Catalog:
3333
def projection_landsat8_item() -> Item:
3434
path = TestCases.get_path("data-files/projection/example-landsat8.json")
3535
return Item.from_file(path)
36+
37+
38+
@pytest.fixture
39+
def sample_item() -> Item:
40+
return Item.from_file(TestCases.get_path("data-files/item/sample-item.json"))

tests/test_item.py

+5
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,8 @@ def test_geo_interface() -> None:
468468
item.to_dict(include_self_link=False, transform_hrefs=False)
469469
== item.__geo_interface__
470470
)
471+
472+
473+
def test_duplicate_self_links(sample_item: pystac.Item) -> None:
474+
# https://github.com/stac-utils/pystac/issues/1102
475+
assert len(sample_item.get_links(rel="self")) == 1

0 commit comments

Comments
 (0)