diff --git a/invenio_records_resources/records/systemfields/files/manager.py b/invenio_records_resources/records/systemfields/files/manager.py index 47771fa8..831d1462 100644 --- a/invenio_records_resources/records/systemfields/files/manager.py +++ b/invenio_records_resources/records/systemfields/files/manager.py @@ -272,22 +272,23 @@ def copy(self, src_files, copy_obj=True): if not self.enabled: return - object_version_ids = [rf.object_version_id for rf in src_files.values() if rf.object_version_id] - if copy_obj: - object_versions = ObjectVersion.copy_many(object_version_ids, self.bucket) + ovs = ObjectVersion.copy_from( + src_files.bucket, destination_bucket=self.bucket + ) else: - object_versions = ObjectVersion.query.filter( - ObjectVersion.version_id.in_(object_version_ids) - ).all() + ovs = ObjectVersion.get_by_bucket(src_files.bucket) - key_object_versions = {obj.key: obj for obj in object_versions} + ovs_by_key = {obj.key: obj for obj in ovs} for key, rf in src_files.items(): if rf.metadata is not None: - self[key] = key_object_versions.get(key), rf.metadata + # this part is slightly confusing, intuitively setter should accept + # only one type of object (FileRecord instance) but it also accepts + # Object Version - between other types + self[key] = ovs_by_key[key], rf.metadata else: - self[key] = key_object_versions.get(key) + self[key] = ovs_by_key[key] self.default_preview = src_files.default_preview self.order = src_files.order