{{ getHistoryNameById(data.item.history_id) }}
@@ -112,8 +117,8 @@ export default {
data() {
const fields = [
{ key: "expand", label: "", class: "col-button" },
- { key: "workflow_id", label: "Workflow", class: "col-name truncate" },
- { key: "history_id", label: "History", class: "col-history truncate" },
+ { key: "workflow_id", label: "Workflow", class: "col-name" },
+ { key: "history_id", label: "History", class: "col-history" },
{ key: "create_time", label: "Invoked", class: "col-small" },
{ key: "update_time", label: "Updated", class: "col-small" },
{ key: "state", class: "col-small" },
From 29f8b1807f550119c787b86c46a168dd0fd3b9e5 Mon Sep 17 00:00:00 2001
From: mvdbeek
Date: Thu, 20 Jan 2022 19:02:15 +0100
Subject: [PATCH 11/11] Handle unique tag name constraints
The idea is to create the tag one by one in a separate session, and
catch any violations.
---
lib/galaxy/model/tags.py | 15 ++++++++++++++-
test/unit/managers/test_TagHandler.py | 6 ++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/lib/galaxy/model/tags.py b/lib/galaxy/model/tags.py
index fd96b8b6634..17260ddfbfa 100644
--- a/lib/galaxy/model/tags.py
+++ b/lib/galaxy/model/tags.py
@@ -2,6 +2,8 @@ import logging
import re
from typing import Dict
+from sqlalchemy.exc import IntegrityError
+from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm.scoping import scoped_session
from sqlalchemy.sql import select
from sqlalchemy.sql.expression import func
@@ -245,7 +247,18 @@ class TagHandler:
return self.sa_session.query(galaxy.model.Tag).filter_by(name=tag_name).first()
def _create_tag_instance(self, tag_name):
- return galaxy.model.Tag(type=0, name=tag_name)
+ # For good performance caller should first check if there's already an appropriate tag
+ Session = sessionmaker(self.sa_session.bind)
+ tag = galaxy.model.Tag(type=0, name=tag_name)
+ with Session() as separate_session:
+ separate_session.add(tag)
+ try:
+ separate_session.commit()
+ separate_session.flush()
+ except IntegrityError:
+ # tag already exists, get from database
+ separate_session.rollback()
+ return self._get_tag(tag_name)
def _get_or_create_tag(self, tag_str):
"""Get or create a Tag object from a tag string."""
diff --git a/test/unit/managers/test_TagHandler.py b/test/unit/managers/test_TagHandler.py
index 7839be7d019..118edddfaa6 100644
--- a/test/unit/managers/test_TagHandler.py
+++ b/test/unit/managers/test_TagHandler.py
@@ -100,6 +100,12 @@ class TagHandlerTestCase(BaseTestCase):
self.tag_handler.delete_item_tags(user=self.user, item=hda)
self.assertEqual(hda.tags, [])
+ def test_unique_constraint_applied(self):
+ tag_name = 'abc'
+ tag = self.tag_handler._create_tag_instance(tag_name)
+ same_tag = self.tag_handler._create_tag_instance(tag_name)
+ assert tag.id == same_tag.id
+
def test_item_has_tag(self):
hda = self._create_vanilla_hda()
tags = ['tag1']