Skip to content

Commit

Permalink
Fix _temp_tensors attribute error (#2044)
Browse files Browse the repository at this point in the history
* fix

* fixes + test

* black
  • Loading branch information
FayazRahman authored Dec 9, 2022
1 parent 28c0b24 commit 3164f88
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
21 changes: 21 additions & 0 deletions deeplake/api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from deeplake.cli.auth import login, logout
from deeplake.util.bugout_reporter import feature_report_path
from rich import print as rich_print
from io import BytesIO

# need this for 32-bit and 64-bit systems to have correct tests
MAX_INT_DTYPE = np.int_.__name__
Expand Down Expand Up @@ -2272,3 +2273,23 @@ def test_invalid_ds_name():
)

verify_dataset_name("hub://test/data-set_123")


def test_pickle_bug(local_ds):
import pickle

file = BytesIO()

with local_ds as ds:
ds.create_tensor("__temp_123")
ds.__temp_123.extend([1, 2, 3, 4, 5])

pickle.dump(local_ds, file)

file.seek(0)
ds = pickle.load(file)

with pytest.raises(TensorDoesNotExistError):
ds["__temp_123"].numpy()

assert ds._temp_tensors == []
8 changes: 7 additions & 1 deletion deeplake/core/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ def __init__(
self._indexing_history: List[int] = []

for temp_tensor in self._temp_tensors:
self.delete_tensor(temp_tensor)
self.delete_tensor(temp_tensor, large_ok=True)
self._temp_tensors = []

def _lock_lost_handler(self):
"""This is called when lock is acquired but lost later on due to slow update."""
Expand Down Expand Up @@ -366,13 +367,18 @@ def __setstate__(self, state: Dict[str, Any]):
state["_commit_hooks"] = {}
state["_waiting_for_view_base_commit"] = False
state["_client"] = state["org_id"] = state["ds_name"] = None
state["_temp_tensors"] = []
self.__dict__.update(state)
self.__dict__["base_storage"] = get_base_storage(self.storage)
# clear cache while restoring
self.storage.clear_cache_without_flush()
self._set_derived_attributes(verbose=False)
self._indexing_history = []

for temp_tensor in self._temp_tensors:
self.delete_tensor(temp_tensor, large_ok=True)
self._temp_tensors = []

def __getitem__(
self,
item: Union[
Expand Down
1 change: 0 additions & 1 deletion deeplake/util/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,4 +846,3 @@ def __init__(self, extension, htype=""):
message = f"{htype}{extension} is not supported"

super().__init__(message)

0 comments on commit 3164f88

Please sign in to comment.