diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js index 8760119a9c..5d734540f9 100644 --- a/chrome/content/zotero/xpcom/data/dataObject.js +++ b/chrome/content/zotero/xpcom/data/dataObject.js @@ -561,8 +561,9 @@ Zotero.DataObject.prototype.hasChanged = function() { } Zotero.DataObject.prototype._initSave = Zotero.Promise.coroutine(function* (env) { - if (!this.libraryID) { - throw new Error("libraryID must be set before saving " + this._objectType); + // Default to user library if not specified + if (this.libraryID === null) { + this.libraryID = Zotero.Libraries.userLibraryID; } env.isNew = !this.id; diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js index e357f5cd56..ced7effe1d 100644 --- a/test/tests/itemTest.js +++ b/test/tests/itemTest.js @@ -2,20 +2,17 @@ describe("Zotero.Item", function() { describe("#getField()", function () { it("should return false for valid unset fields on unsaved items", function* () { var item = new Zotero.Item('book'); - item.libraryID = Zotero.Libraries.userLibraryID; assert.equal(item.getField('rights'), false); }); it("should return false for valid unset fields on unsaved items after setting on another field", function* () { var item = new Zotero.Item('book'); - item.libraryID = Zotero.Libraries.userLibraryID; item.setField('title', 'foo'); assert.equal(item.getField('rights'), false); }); it("should return false for invalid unset fields on unsaved items after setting on another field", function* () { var item = new Zotero.Item('book'); - item.libraryID = Zotero.Libraries.userLibraryID; item.setField('title', 'foo'); assert.equal(item.getField('invalid'), false); }); @@ -25,11 +22,9 @@ describe("Zotero.Item", function() { it("should create a child note", function () { return Zotero.DB.executeTransaction(function* () { var item = new Zotero.Item('book'); - item.libraryID = Zotero.Libraries.userLibraryID; var parentItemID = yield item.save(); item = new Zotero.Item('note'); - item.libraryID = Zotero.Libraries.userLibraryID; item.parentID = parentItemID; var childItemID = yield item.save(); diff --git a/test/tests/itemsTest.js b/test/tests/itemsTest.js index 735c501d25..093c63cf1b 100644 --- a/test/tests/itemsTest.js +++ b/test/tests/itemsTest.js @@ -3,7 +3,6 @@ describe("Zotero.Items", function() { it("should return a libraryID and key within a transaction", function* () { return Zotero.DB.executeTransaction(function* () { var item = new Zotero.Item('book'); - item.libraryID = Zotero.Libraries.userLibraryID; var itemID = yield item.save(); var {libraryID, key} = Zotero.Items.getLibraryAndKeyFromID(itemID); @@ -19,7 +18,6 @@ describe("Zotero.Items", function() { try { yield Zotero.DB.executeTransaction(function* () { var item = new Zotero.Item('book'); - item.libraryID = Zotero.Libraries.userLibraryID; itemID = yield item.save(); throw 'Aborting transaction -- ignore'; });