diff --git a/src/tagstudio/core/library/alchemy/library.py b/src/tagstudio/core/library/alchemy/library.py index a25231e95..a0e7f8e23 100644 --- a/src/tagstudio/core/library/alchemy/library.py +++ b/src/tagstudio/core/library/alchemy/library.py @@ -1898,14 +1898,14 @@ def mirror_entry_fields(self, *entries: Entry) -> None: """Mirror fields among multiple Entry items.""" fields = {} # load all fields - existing_fields = {field.type_key for field in entries[0].fields} for entry in entries: for entry_field in entry.fields: fields[entry_field.type_key] = entry_field - # assign the field to all entries + # assign the fields to all entries for entry in entries: for field_key, field in fields.items(): # pyright: ignore[reportUnknownVariableType] + existing_fields = {entry_field.type_key for entry_field in entry.fields} if field_key not in existing_fields: self.add_field_to_entry( entry_id=entry.id, @@ -1913,6 +1913,19 @@ def mirror_entry_fields(self, *entries: Entry) -> None: value=field.value, ) + def mirror_entry_tags(self, *entries: Entry) -> None: + """Mirror tags among multiple Entry items.""" + tag_ids_set = set() + entry_ids = [] + # load all entries and tags + for entry in entries: + entry_ids.append(entry.id) + for tag in entry.tags: + tag_ids_set.add(tag.id) + tag_ids = list(tag_ids_set) + # assign the tags to all entries + self.add_tags_to_entries(entry_ids, tag_ids) + def merge_entries(self, from_entry: Entry, into_entry: Entry) -> bool: """Add fields and tags from the first entry to the second, and then delete the first.""" success = True diff --git a/src/tagstudio/core/library/alchemy/registries/dupe_files_registry.py b/src/tagstudio/core/library/alchemy/registries/dupe_files_registry.py index d99a4f498..bb2309c51 100644 --- a/src/tagstudio/core/library/alchemy/registries/dupe_files_registry.py +++ b/src/tagstudio/core/library/alchemy/registries/dupe_files_registry.py @@ -49,18 +49,29 @@ def refresh_dupe_files(self, results_filepath: str | Path): path_relative = file_path.relative_to(library_dir) except ValueError: # The file is not in the library directory + logger.error("File not in library directory", file_path=file_path) continue results = self.library.search_library( BrowsingState.from_path(path_relative), 500 ) - entries = self.library.get_entries(results.ids) if not results: # file not in library + logger.error("No Entry matching file", path_relative=path_relative) continue - files.append(entries[0]) + entry = self.library.get_entry_full(results.ids[0]) + + if not entry: + # file not in library + logger.error( + "Unable to get entry", + entry_id=results.ids[0], + path_relative=path_relative, + ) + continue + files.append(entry) if not len(files) > 1: # only one file in the group, nothing to do diff --git a/src/tagstudio/qt/mixed/mirror_entries_modal.py b/src/tagstudio/qt/mixed/mirror_entries_modal.py index d67cf12ed..0e144c59a 100644 --- a/src/tagstudio/qt/mixed/mirror_entries_modal.py +++ b/src/tagstudio/qt/mixed/mirror_entries_modal.py @@ -95,6 +95,8 @@ def mirror_entries_runnable(self): mirrored: list = [] lib = self.driver.lib for i, entries in enumerate(self.tracker.groups): + # mirror tags and fields + lib.mirror_entry_tags(*entries) lib.mirror_entry_fields(*entries) sleep(0.005) yield i