diff --git a/cloud_storage/__init__.py b/cloud_storage/__init__.py index 45fc226..3a2ec68 100644 --- a/cloud_storage/__init__.py +++ b/cloud_storage/__init__.py @@ -1,7 +1,7 @@ # Copyright (c) 2024, AgriTheory and contributors # For license information, please see license.txt -__version__ = "15.7.2" +__version__ = "15.7.3" import frappe.desk.form.load diff --git a/cloud_storage/cloud_storage/overrides/file.py b/cloud_storage/cloud_storage/overrides/file.py index b509f34..94c9c74 100644 --- a/cloud_storage/cloud_storage/overrides/file.py +++ b/cloud_storage/cloud_storage/overrides/file.py @@ -53,7 +53,9 @@ def validate(self) -> None: PATH: frappe/core/doctype/file/file.py METHOD: validate """ - self.associate_files() + # guard against recursion: associate_files() can save another File, re-entering validate + if not self.flags.associating_files: + self.associate_files() if self.flags.cloud_storage or self.flags.ignore_file_validate: return if not self.is_remote_file: @@ -228,10 +230,16 @@ def associate_files( existing_file = frappe.get_doc("File", associated_doc) existing_file.attached_to_doctype = attached_to_doctype existing_file.attached_to_name = attached_to_name - existing_file.append( - "file_association", - add_child_file_association(attached_to_doctype, attached_to_name), + already_linked = any( + assoc.link_doctype == attached_to_doctype and assoc.link_name == attached_to_name + for assoc in existing_file.file_association ) + if not already_linked: + existing_file.append( + "file_association", + add_child_file_association(attached_to_doctype, attached_to_name), + ) + existing_file.flags.associating_files = True existing_file.save() else: if self.file_association: