Skip to content

Commit d1fad69

Browse files
committed
fix: raise error if writing to url
This is in DefaultStacIO ... other StacIOs could support writing to urls, if they want.
1 parent 215e484 commit d1fad69

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- Removed documentation references to `to_dict` methods returning JSON ([#1074](https://github.com/stac-utils/pystac/pull/1074))
1818
- Expand support for previous extension schema URIs ([#1091](https://github.com/stac-utils/pystac/pull/1091))
1919
- Use `pyproject.toml` instead of `setup.py` ([#1100](https://github.com/stac-utils/pystac/pull/1100))
20+
- `DefaultStacIO` now raises an error if it tries to write to a non-local url ([#1107](https://github.com/stac-utils/pystac/pull/1107))
2021

2122
### Deprecated
2223

pystac/stac_io.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ def write_text_to_href(self, href: str, txt: str) -> None:
326326
href : The path to which the file will be written.
327327
txt : The string content to write to the file.
328328
"""
329+
if _is_url(href):
330+
raise NotImplementedError("DefaultStacIO cannot write to urls")
329331
href = os.fspath(href)
330332
dirname = os.path.dirname(href)
331333
if dirname != "" and not os.path.isdir(dirname):

tests/test_stac_io.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import tempfile
44
import unittest
5+
from pathlib import Path
56

67
import pytest
78

@@ -142,3 +143,10 @@ def test_retry_stac_io_404() -> None:
142143
"https://planetarycomputer.microsoft.com"
143144
"/api/stac/v1/collections/not-a-collection-id"
144145
)
146+
147+
148+
def test_save_http_href_errors(tmp_path: Path) -> None:
149+
catalog = pystac.Catalog(id="test-catalog", description="")
150+
catalog.set_self_href("http://pystac.test/catalog.json")
151+
with pytest.raises(NotImplementedError):
152+
catalog.save_object()

0 commit comments

Comments
 (0)