Skip to content

Commit

Permalink
Remove ShelveStore (#4148)
Browse files Browse the repository at this point in the history
* Remove ShelveStore

Signed-off-by: Ankita Katiyar <[email protected]>

* Remove ShelveStore

Signed-off-by: Ankita Katiyar <[email protected]>

---------

Signed-off-by: Ankita Katiyar <[email protected]>
  • Loading branch information
ankatiyar authored Sep 9, 2024
1 parent d6f8ae5 commit 66e5e07
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 136 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Fixed bug where using dataset factories breaks with `ThreadRunner`.

## Breaking changes to the API
* Removed `ShelveStore` to address a security vulnerability.

## Documentation changes
* Fix logo on PyPI page.
Expand Down

This file was deleted.

46 changes: 0 additions & 46 deletions kedro/framework/session/shelvestore.py

This file was deleted.

7 changes: 3 additions & 4 deletions tests/framework/project/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from kedro.config import OmegaConfigLoader
from kedro.framework.context.context import KedroContext
from kedro.framework.project import configure_project, settings, validate_settings
from kedro.framework.session.shelvestore import ShelveStore
from kedro.framework.session.store import BaseSessionStore
from kedro.io import DataCatalog

Expand Down Expand Up @@ -40,8 +39,8 @@ def mock_package_name_with_settings_file(tmpdir):
DISABLE_HOOKS_FOR_PLUGINS = ("kedro-viz",)
from kedro.framework.session.shelvestore import ShelveStore
SESSION_STORE_CLASS = ShelveStore
from kedro.framework.session.store import BaseSessionStore
SESSION_STORE_CLASS = BaseSessionStore
SESSION_STORE_ARGS = {{
"path": "./sessions"
}}
Expand Down Expand Up @@ -103,7 +102,7 @@ def test_settings_after_configuring_project_shows_updated_values(
configure_project(mock_package_name_with_settings_file)
assert len(settings.HOOKS) == 1 and isinstance(settings.HOOKS[0], ProjectHooks)
assert settings.DISABLE_HOOKS_FOR_PLUGINS.to_list() == ["kedro-viz"]
assert settings.SESSION_STORE_CLASS is ShelveStore
assert settings.SESSION_STORE_CLASS is BaseSessionStore
assert settings.SESSION_STORE_ARGS == {"path": "./sessions"}
assert settings.CONTEXT_CLASS is MyContext
assert settings.CONF_SOURCE == "test_conf"
Expand Down
37 changes: 0 additions & 37 deletions tests/framework/session/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
ValidationError,
Validator,
_HasSharedParentClassValidator,
_IsSubclassValidator,
_ProjectSettings,
)
from kedro.framework.session import KedroSession
from kedro.framework.session.session import KedroSessionError
from kedro.framework.session.shelvestore import ShelveStore
from kedro.framework.session.store import BaseSessionStore
from kedro.utils import _has_rich_handler

Expand Down Expand Up @@ -235,21 +233,6 @@ class MockSettings(_ProjectSettings):
)


@pytest.fixture
def mock_settings_shelve_session_store(mocker, fake_project):
shelve_location = fake_project / "nested" / "sessions"

class MockSettings(_ProjectSettings):
_SESSION_STORE_CLASS = _IsSubclassValidator(
"SESSION_STORE_CLASS", default=lambda *_: ShelveStore
)
_SESSION_STORE_ARGS = Validator(
"SESSION_STORE_ARGS", default={"path": shelve_location.as_posix()}
)

return _mock_imported_settings_paths(mocker, MockSettings())


@pytest.fixture
def fake_session_id(mocker):
session_id = "fake_session_id"
Expand Down Expand Up @@ -502,26 +485,6 @@ def test_default_store(self, fake_project, fake_session_id, caplog):
]
assert actual_log_messages == expected_log_messages

@pytest.mark.usefixtures("mock_settings_shelve_session_store")
def test_shelve_store(self, fake_project, fake_session_id, caplog, mocker):
mocker.patch("pathlib.Path.is_file", return_value=True)
shelve_location = fake_project / "nested" / "sessions"
other = KedroSession.create(fake_project)
assert other._store.__class__ is ShelveStore
assert other._store._path == shelve_location.as_posix()
assert other._store._location == shelve_location / fake_session_id / "store"
assert other._store._session_id == fake_session_id
assert not shelve_location.is_dir()

other.close() # session data persisted
assert shelve_location.is_dir()
actual_log_messages = [
rec.getMessage()
for rec in caplog.records
if rec.name == STORE_LOGGER_NAME and rec.levelno == logging.DEBUG
]
assert not actual_log_messages

def test_wrong_store_type(self, mock_settings_file_bad_session_store_class):
pattern = (
"Invalid value 'tests.framework.session.test_session.BadStore' received "
Expand Down
43 changes: 0 additions & 43 deletions tests/framework/session/test_store.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import logging
from pathlib import Path

import pytest

from kedro.framework.session.shelvestore import ShelveStore
from kedro.framework.session.store import BaseSessionStore

FAKE_SESSION_ID = "fake_session_id"
Expand Down Expand Up @@ -48,42 +44,3 @@ def test_save(self, caplog):
if rec.name == STORE_LOGGER_NAME and rec.levelno == logging.DEBUG
]
assert actual_debug_messages == expected_debug_messages


@pytest.fixture
def shelve_path(tmp_path):
return Path(tmp_path / "path" / "to" / "sessions")


class TestShelveStore:
def test_empty(self, shelve_path):
shelve = ShelveStore(str(shelve_path), FAKE_SESSION_ID)
assert shelve == {}
assert shelve._location == shelve_path / FAKE_SESSION_ID / "store"
assert not shelve_path.exists()

def test_save(self, shelve_path):
assert not shelve_path.exists()

shelve = ShelveStore(str(shelve_path), FAKE_SESSION_ID)
shelve["shelve_path"] = shelve_path
shelve.save()

assert (shelve_path / FAKE_SESSION_ID).is_dir()

reloaded = ShelveStore(str(shelve_path), FAKE_SESSION_ID)
assert reloaded == {"shelve_path": shelve_path}

def test_update(self, shelve_path):
shelve = ShelveStore(str(shelve_path), FAKE_SESSION_ID)
shelve["shelve_path"] = shelve_path
shelve.save()

shelve.update(new_key="new_value")
del shelve["shelve_path"]
reloaded = ShelveStore(str(shelve_path), FAKE_SESSION_ID)
assert reloaded == {"shelve_path": shelve_path} # changes not saved yet

shelve.save()
reloaded = ShelveStore(str(shelve_path), FAKE_SESSION_ID)
assert reloaded == {"new_key": "new_value"}

0 comments on commit 66e5e07

Please sign in to comment.