Skip to content

Commit

Permalink
commands ensure file object types in rollback commands
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoCampinoti94 committed Jan 17, 2025
1 parent 6e3d2f6 commit e711ee7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions digiarch/commands/edit/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def _handler(_ctx: Context, _avid: AVID, database: FilesDB, event: Event, file:
table = database.statutory_files
else:
return
if not isinstance(file, table.model):
raise TypeError(f"{type(file)} is not {table.model.__name__}")
prev_value, next_value = event.data
setattr(file, property_name, prev_value)
table.update(file)
Expand Down
3 changes: 3 additions & 0 deletions digiarch/commands/edit/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from acacore.database import FilesDB
from acacore.models.event import Event
from acacore.models.file import BaseFile
from acacore.models.file import OriginalFile
from acacore.utils.click import end_program
from acacore.utils.click import param_callback_regex
from acacore.utils.click import start_program
Expand All @@ -31,6 +32,8 @@
def rollback_rename_original(_ctx: Context, avid: AVID, database: FilesDB, event: Event, file: BaseFile | None):
if not file:
raise FileNotFoundError(f"No file with UUID {event.file_uuid}")
if not isinstance(file, OriginalFile):
raise TypeError(f"{type(file)} is not OriginalFile")

file.root = avid.path
current_path: Path = file.relative_path
Expand Down
2 changes: 1 addition & 1 deletion digiarch/commands/extract/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def rollback_extract_remove_child(ctx: Context, avid: AVID, database: FilesDB, f


def rollback_extract(ctx: Context, avid: AVID, database: FilesDB, _event: Event, file: BaseFile | None):
if not file:
if not file or not isinstance(file, OriginalFile):
return

for child in database.original_files.select("parent = ?", [str(file.uuid)]).fetchall():
Expand Down

0 comments on commit e711ee7

Please sign in to comment.