Skip to content

Commit 215e484

Browse files
committed
Merge branch 'v1.7'
2 parents 5385ca6 + 0496011 commit 215e484

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
- Catalog `get_item()`. Use `get_items(id)` instead ([#1075](https://github.com/stac-utils/pystac/pull/1075))
2525
- Catalog and Collection `get_all_items`. Use `get_items(recursive=True)` instead ([#1075](https://github.com/stac-utils/pystac/pull/1075))
2626

27+
## [v1.7.3]
28+
29+
### Fixed
30+
31+
- Duplicate `self` links in Items ([#1103](https://github.com/stac-utils/pystac/pull/1103))
32+
2733
## [v1.7.2]
2834

2935
### Fixed
@@ -698,7 +704,8 @@ use `Band.create`
698704

699705
Initial release.
700706

701-
[Unreleased]: <https://github.com/stac-utils/pystac/compare/v1.7.2..main>
707+
[Unreleased]: <https://github.com/stac-utils/pystac/compare/v1.7.3..main>
708+
[v1.7.3]: <https://github.com/stac-utils/pystac/compare/v1.7.2..v1.7.3>
702709
[v1.7.2]: <https://github.com/stac-utils/pystac/compare/v1.7.1..v1.7.2>
703710
[v1.7.1]: <https://github.com/stac-utils/pystac/compare/v1.7.0..v1.7.1>
704711
[v1.7.0]: <https://github.com/stac-utils/pystac/compare/v1.6.1..v1.7.0>

pystac/item.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Type, TypeVar, Union, cast
77

88
import pystac
9-
from pystac import STACError, STACObjectType
9+
from pystac import RelType, STACError, STACObjectType
1010
from pystac.asset import Asset
1111
from pystac.catalog import Catalog
1212
from pystac.collection import Collection
@@ -473,13 +473,9 @@ def from_dict(
473473
assets={k: Asset.from_dict(v) for k, v in assets.items()},
474474
)
475475

476-
has_self_link = False
477476
for link in links:
478-
has_self_link |= link["rel"] == pystac.RelType.SELF
479-
item.add_link(Link.from_dict(link))
480-
481-
if not has_self_link and href is not None:
482-
item.add_link(Link.self_href(href))
477+
if href is None or link.get("rel", None) != RelType.SELF:
478+
item.add_link(Link.from_dict(link))
483479

484480
if root:
485481
item.set_root(root)

pystac/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
from typing import Optional
33

4-
__version__ = "1.7.2"
4+
__version__ = "1.7.3"
55
"""Library version"""
66

77

tests/conftest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# TODO move all test case code to this file
22

3-
from pathlib import Path
43
from datetime import datetime
4+
from pathlib import Path
55

66
import pytest
77

88
from pystac import Catalog, Collection, Item
99

1010
from .utils import ARBITRARY_BBOX, ARBITRARY_EXTENT, ARBITRARY_GEOM, TestCases
1111

12-
1312
here = Path(__file__).resolve().parent
1413

1514

@@ -46,3 +45,8 @@ def projection_landsat8_item() -> Item:
4645

4746
def get_data_file(rel_path: str) -> str:
4847
return str(here / "data-files" / rel_path)
48+
49+
50+
@pytest.fixture
51+
def sample_item() -> Item:
52+
return Item.from_file(TestCases.get_path("data-files/item/sample-item.json"))

tests/test_item.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import tempfile
66
import unittest
77
from copy import deepcopy
8+
from pathlib import Path
89
from typing import Any, Dict, Optional
910

1011
import dateutil.relativedelta
@@ -470,3 +471,12 @@ def test_geo_interface() -> None:
470471
item.to_dict(include_self_link=False, transform_hrefs=False)
471472
== item.__geo_interface__
472473
)
474+
475+
476+
def test_duplicate_self_links(tmp_path: Path, sample_item: pystac.Item) -> None:
477+
# https://github.com/stac-utils/pystac/issues/1102
478+
assert len(sample_item.get_links(rel="self")) == 1
479+
path = tmp_path / "item.json"
480+
sample_item.save_object(include_self_link=True, dest_href=str(path))
481+
sample_item = Item.from_file(str(path))
482+
assert len(sample_item.get_links(rel="self")) == 1

0 commit comments

Comments
 (0)