Skip to content

Commit

Permalink
fix(cache): update cache after deleting file
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Sep 24, 2024
1 parent 20113b3 commit e0fd6b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion antarest/study/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
)
from antarest.core.filetransfer.model import FileDownloadTaskDTO
from antarest.core.filetransfer.service import FileTransferManager
from antarest.core.interfaces.cache import ICache
from antarest.core.interfaces.cache import CacheConstants, ICache
from antarest.core.interfaces.eventbus import Event, EventType, IEventBus
from antarest.core.jwt import DEFAULT_ADMIN_USER, JWTGroup, JWTUser
from antarest.core.model import JSON, SUB_JSON, PermissionInfo, PublicMode, StudyPermissionType
Expand Down Expand Up @@ -2670,3 +2670,8 @@ def delete_file_or_folder(self, study_id: str, path: str, current_user: JWTUser)
study_tree["user"].delete(url[1:])
except ChildNotFoundError as e:
raise FileDeletionNotAllowed(f"the given path doesn't exist: {e.detail}")

# update cache
cache_id = f"{CacheConstants.RAW_STUDY}/{study.id}"
updated_tree = self.storage_service.raw_study_service.get_raw(study, False).tree.get()
self.storage_service.get_storage(study).cache.put(cache_id, updated_tree) # type: ignore
17 changes: 16 additions & 1 deletion tests/integration/raw_studies_blueprint/test_fetch_raw_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,21 +276,36 @@ def test_delete_raw(client: TestClient, user_access_token: str, internal_study_i
content = io.BytesIO(b"This is the end!")
file_1_path = "user/file_1.txt"
file_2_path = "user/folder/file_2.txt"
for f in [file_1_path, file_2_path]:
file_3_path = "user/folder_2/file_3.txt"
for f in [file_1_path, file_2_path, file_3_path]:
# Creates a file / folder inside user folder.
res = client.put(
f"/v1/studies/{internal_study_id}/raw", params={"path": f, "create_missing": True}, files={"file": content}
)
assert res.status_code == 204, res.json()

# Deletes the file / folder
if f == file_2_path:
f = "user/folder"
res = client.delete(f"/v1/studies/{internal_study_id}/raw?path={f}")
assert res.status_code == 200
# Asserts it doesn't exist anymore
res = client.get(f"/v1/studies/{internal_study_id}/raw?path={f}")
assert res.status_code == 404
assert "not a child of" in res.json()["description"]

# checks debug view
res = client.get(f"/v1/studies/{internal_study_id}/raw?path=&depth=-1")
assert res.status_code == 200
tree = res.json()["user"]
if f == file_3_path:
# asserts the folder that wasn't deleted is still here.
assert list(tree.keys()) == ["expansion", "folder_2"]
assert tree["folder_2"] == {}
else:
# asserts deleted files cannot be seen inside the debug view
assert list(tree.keys()) == ["expansion"]

# =============================
# ERRORS
# =============================
Expand Down

0 comments on commit e0fd6b1

Please sign in to comment.