diff --git a/lib/private/SystemTag/SystemTagManager.php b/lib/private/SystemTag/SystemTagManager.php
index 7c21c0e004eab91a8c2d2db985a7cf687c36b11a..d0854e885eb484828bacd9986145231224f83a27 100644
--- a/lib/private/SystemTag/SystemTagManager.php
+++ b/lib/private/SystemTag/SystemTagManager.php
@@ -400,6 +400,9 @@ class SystemTagManager implements ISystemTagManager {
 					'gid' => $query->createParameter('gid'),
 				]);
 			foreach ($groupIds as $groupId) {
+				if ($groupId === '') {
+					continue;
+				}
 				$query->setParameter('gid', $groupId);
 				$query->execute();
 			}
diff --git a/tests/lib/SystemTag/SystemTagManagerTest.php b/tests/lib/SystemTag/SystemTagManagerTest.php
index e697e373465aeb44f2dd5a9b5d10551fa7058bee..61fac99ca6c77fe03760bde613dfdc6eb2fbb332 100644
--- a/tests/lib/SystemTag/SystemTagManagerTest.php
+++ b/tests/lib/SystemTag/SystemTagManagerTest.php
@@ -516,6 +516,15 @@ class SystemTagManagerTest extends TestCase {
 		$this->assertEquals([], $this->tagManager->getTagGroups($tag2));
 	}
 
+	/**
+	 * empty groupIds should be ignored
+	 */
+	public function testEmptyTagGroup() {
+		$tag1 = $this->tagManager->createTag('tag1', true, false);
+		$this->tagManager->setTagGroups($tag1, ['']);
+		$this->assertEquals([], $this->tagManager->getTagGroups($tag1));
+	}
+
 	/**
 	 * @param ISystemTag $tag1
 	 * @param ISystemTag $tag2