Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Error message for VersionNotFoundError to handle Permission related issues better #1881

Merged
merged 10 commits into from
Oct 3, 2022
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
## Bug fixes and other changes
* Fixed `kedro micropkg pull` for packages on PyPI.
* Fixed `format` in `save_args` for `SparkHiveDataSet`, previously it didn't allow you to save it as delta format.
* Updated error message for `VersionNotFoundError` to handle insufficient permission issues for cloud storage.

## Minor breaking changes to the API

Expand Down
11 changes: 9 additions & 2 deletions kedro/io/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,16 @@ def _fetch_latest_load_version(self) -> str:
most_recent = next(
(path for path in version_paths if self._exists_function(path)), None
)

protocol = getattr(self, "_protocol", None)
if not most_recent:
raise VersionNotFoundError(f"Did not find any versions for {self}")
if protocol in CLOUD_PROTOCOLS:
message = (
f"Did not find any versions for {self}. This could be "
f"due to insufficient permission."
)
else:
message = f"Did not find any versions for {self}"
raise VersionNotFoundError(message)

return PurePath(most_recent).parent.name

Expand Down
13 changes: 12 additions & 1 deletion tests/io/test_data_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
LambdaDataSet,
MemoryDataSet,
)
from kedro.io.core import VERSION_FORMAT, generate_timestamp
from kedro.io.core import VERSION_FORMAT, Version, generate_timestamp


@pytest.fixture
Expand Down Expand Up @@ -652,3 +652,14 @@ def test_replacing_nonword_characters(self):
assert "ds2_spark" in catalog.datasets.__dict__
assert "ds3__csv" in catalog.datasets.__dict__
assert "jalapeño" in catalog.datasets.__dict__

def test_no_versions_with_cloud_protocol(self):
"""Check the error if no versions are available for load from cloud storage"""
version = Version(load=None, save=None)
versioned_dataset = CSVDataSet("s3://bucket/file.csv", version=version)
pattern = re.escape(
f"Did not find any versions for {versioned_dataset}. "
f"This could be due to insufficient permission."
)
with pytest.raises(DataSetError, match=pattern):
versioned_dataset.load()