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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AL-1710] Allow branch creation when dataset is locked #1584

Merged
merged 3 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions hub/api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
InvalidTensorNameError,
PathNotEmptyException,
BadRequestException,
ReadOnlyModeError,
)
from hub.constants import MB

Expand Down Expand Up @@ -1396,3 +1397,13 @@ def test_pyav_not_installed(local_ds, video_paths):
with pytest.raises(hub.util.exceptions.CorruptedSampleError):
local_ds.videos.append(hub.read(video_paths["mp4"][0]))
hub.core.compression._PYAV_INSTALLED = pyav_installed


def test_create_branch_when_locked_out(local_ds):
local_ds.read_only = True
local_ds._locked_out = True
with pytest.raises(ReadOnlyModeError):
local_ds.create_tensor("x")
local_ds.checkout("branch", create=True)
assert local_ds.branch == "branch"
local_ds.create_tensor("x")
18 changes: 15 additions & 3 deletions hub/core/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,16 +842,28 @@ def _checkout(
raise Exception(
"Cannot perform version control operations on a filtered dataset view."
)

if self._locked_out:
self.storage.disable_readonly()
self._read_only = False
base_storage = get_base_storage(self.storage)
base_storage.disable_readonly()
try_flushing(self)

self._initial_autoflush.append(self.storage.autoflush)
self.storage.autoflush = False
err = False
try:
self._unlock()
checkout(self, address, create, hash)
self._lock()
except Exception as e:
err = True
if self._locked_out:
self.storage.enable_readonly()
self._read_only = True
base_storage.enable_readonly()
raise e
finally:
if not (err and self._locked_out):
self._lock()
self.storage.autoflush = self._initial_autoflush.pop()
self._info = None
self._ds_diff = None
Expand Down