Skip to content

Commit 9ffb850

Browse files
authored
Set collection to None in item constructor when there is no collection (#1400)
* fix: set collection to None in item constructor * chore: update changelog
1 parent a5c3e80 commit 9ffb850

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
### Fixed
1919

2020
- Make `get_all_collections` properly recursive ([#1361](https://github.com/stac-utils/pystac/pull/1361))
21+
- Set `Item::collection` to `None` when there is no collection ([#1400](https://github.com/stac-utils/pystac/pull/1400))
2122

2223
### Removed
2324

pystac/item.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ def __init__(
158158
self.set_self_href(href)
159159

160160
self.collection_id: str | None = None
161-
if collection is not None:
161+
if collection is None:
162+
self.collection = None
163+
else:
162164
if isinstance(collection, Collection):
163165
self.set_collection(collection)
164166
else:

tests/test_item.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,3 +692,8 @@ def test_copy_with_unresolveable_root(item: Item) -> None:
692692
)
693693
)
694694
copy.deepcopy(item)
695+
696+
697+
def test_no_collection(item: Item) -> None:
698+
# https://github.com/stac-utils/stac-api-validator/issues/527
699+
assert item.collection is None

0 commit comments

Comments
 (0)