From d6fc071139a19a9334b024bffbcb219d204fe283 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 19 Dec 2025 16:16:09 -0500 Subject: [PATCH] Load attachment data when handling file renaming on item metadata change File renaming has a Notifier handler for item modifications that needs best-attachment titles, but attachments and their item data might not be loaded even when parent items are. (This came up when migrating fields from Extra after a global schema update before the main window had loaded.) --- chrome/content/zotero/renameFiles.mjs | 1 + chrome/content/zotero/xpcom/data/item.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/renameFiles.mjs b/chrome/content/zotero/renameFiles.mjs index cedc0f1124..871ea06b8d 100644 --- a/chrome/content/zotero/renameFiles.mjs +++ b/chrome/content/zotero/renameFiles.mjs @@ -285,6 +285,7 @@ export function registerAutoRenameFileFromParent() { } } + await attachmentItem.loadDataType('itemData'); let previousMetadataBaseName = Zotero.Attachments.getFileBaseNameFromItem( parentItemBefore, { attachmentTitle: attachmentItem.getField('title') } ); diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index a7f6e97e3f..228c9062ed 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -3921,7 +3921,7 @@ Zotero.Item.prototype.getBestAttachments = async function () { + "AND IA.itemID NOT IN (SELECT itemID FROM deletedItems) " + "ORDER BY contentType='application/pdf' DESC, value=? DESC, dateAdded ASC"; var itemIDs = await Zotero.DB.columnQueryAsync(sql, [this.id, url]); - return this.ObjectsClass.get(itemIDs); + return await this.ObjectsClass.getAsync(itemIDs); };