diff --git a/server/lib/scene/scene.update.js b/server/lib/scene/scene.update.js index e8cd3ecb6c..7b64f72fff 100644 --- a/server/lib/scene/scene.update.js +++ b/server/lib/scene/scene.update.js @@ -34,13 +34,12 @@ async function update(selector, scene) { await existingScene.update(scene); - await db.TagScene.destroy({ - where: { - scene_id: existingScene.id, - }, - }); - if (scene.tags) { + await db.TagScene.destroy({ + where: { + scene_id: existingScene.id, + }, + }); await db.TagScene.bulkCreate( scene.tags.map((tag) => ({ scene_id: existingScene.id, diff --git a/server/test/lib/scene/scene.update.test.js b/server/test/lib/scene/scene.update.test.js index 5ccde75063..7569ee6596 100644 --- a/server/test/lib/scene/scene.update.test.js +++ b/server/test/lib/scene/scene.update.test.js @@ -34,6 +34,17 @@ describe('scene.update', () => { assertSinon.calledOnce(brain.addNamedEntity); assertSinon.calledOnce(brain.removeNamedEntity); }); + it('should not delete tags when patching scene', async () => { + const scene = await sceneManager.update('test-scene', { + name: 'Name updated', + tags: [{ name: 'tag 1' }], + }); + expect(scene.tags).deep.eq([{ name: 'tag 1' }]); + const scene2 = await sceneManager.update('test-scene', { + name: 'Name updated 2', + }); + expect(scene2.tags).deep.eq([{ name: 'tag 1' }]); + }); it('should return not found', async () => { const promise = sceneManager.update('not-found-scene', { name: 'Updated scene',