Skip to content

Commit

Permalink
Update Error message for VersionNotFoundError to handle Permission …
Browse files Browse the repository at this point in the history
…related issues better (#1881)

* Update message for VersionNotFoundError

Signed-off-by: Ankita Katiyar <110245118+ankatiyar@users.noreply.github.com>

* Add test for VersionNotFoundError for cloud protocols

* Update test_data_catalog.py

Update NoVersionFoundError test

* minor linting update

* update docs link + styling changes

* Revert "update docs link + styling changes"

This reverts commit 6088e00.

* Update test with styling changes

* Update RELEASE.md

Signed-off-by: ankatiyar <ankitakatiyar2401@gmail.com>

Signed-off-by: Ankita Katiyar <110245118+ankatiyar@users.noreply.github.com>
Signed-off-by: ankatiyar <ankitakatiyar2401@gmail.com>
Co-authored-by: Ahdra Merali <90615669+AhdraMeraliQB@users.noreply.github.com>
Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>
  • Loading branch information
2 people authored and Ahdra Merali committed Oct 21, 2022
1 parent 57384cc commit d6feaac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
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()

0 comments on commit d6feaac

Please sign in to comment.