From a5bbc6f680974ea12ec8efad5574a3715dbb7ea0 Mon Sep 17 00:00:00 2001 From: Wahaj Javed Date: Tue, 23 Nov 2021 01:13:22 +0500 Subject: [PATCH] fixtures: handles insert/replace scenario with files * Deletes the files and returns a 404 message upon insert or replace files when using the --skip-files flag * Fixes #2150 --- cernopendata/modules/fixtures/cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cernopendata/modules/fixtures/cli.py b/cernopendata/modules/fixtures/cli.py index 7f539bd8d2..5833481db9 100644 --- a/cernopendata/modules/fixtures/cli.py +++ b/cernopendata/modules/fixtures/cli.py @@ -104,7 +104,7 @@ def update_record(pid, schema, data, files, skip_files): """Updates the given record.""" record = Record.get_record(pid.object_uuid) with db.session.begin_nested(): - if record.files and not skip_files: + if record.files and skip_files: bucket_id = record.files.bucket bucket = Bucket.get(bucket_id.id) for o in ObjectVersion.get_by_bucket(bucket).all(): @@ -114,6 +114,7 @@ def update_record(pid, schema, data, files, skip_files): record=record.model, bucket=bucket ).delete() + Bucket.delete(bucket.id) bucket_id.remove() db.session.commit() record.update(data)