Skip to content

Commit

Permalink
[AL-1710] Allow branch creation when dataset is locked (#1584)
Browse files Browse the repository at this point in the history
  • Loading branch information
farizrahman4u committed Apr 7, 2022
1 parent 9fd9a23 commit c40a82b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
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.util.pretty_print import summary_tensor, summary_dataset
from hub.constants import MB
Expand Down Expand Up @@ -1427,3 +1428,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 @@ -848,16 +848,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

0 comments on commit c40a82b

Please sign in to comment.