Skip to content

Commit c254d6c

Browse files
authored
Merge pull request #20925 from mvdbeek/fix_sessionless_tag_creation
[25.0] Fix sessionless tag creation
2 parents 5443051 + 1e75106 commit c254d6c

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

lib/galaxy/model/store/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ class SessionlessContext:
227227
def __init__(self) -> None:
228228
self.objects: Dict[Type, Dict] = defaultdict(dict)
229229

230+
def execute(self, query: Any, *args, **kwargs) -> Any:
231+
pass
232+
233+
def delete(self, obj: model.RepresentById) -> None:
234+
self.objects[obj.__class__].pop(obj.id, None)
235+
236+
def scalars(self, query: Any, *args, **kwargs) -> Any:
237+
pass
238+
230239
def commit(self) -> None:
231240
pass
232241

lib/galaxy/model/tags.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Optional,
77
Tuple,
88
TYPE_CHECKING,
9+
Union,
910
)
1011

1112
from sqlalchemy.exc import IntegrityError
@@ -29,6 +30,7 @@
2930

3031
if TYPE_CHECKING:
3132
from galaxy.model import User
33+
from galaxy.model.store import SessionlessContext
3234

3335
log = logging.getLogger(__name__)
3436

@@ -46,7 +48,9 @@ class TagHandler:
4648
Manages CRUD operations related to tagging objects.
4749
"""
4850

49-
def __init__(self, sa_session: scoped_session, galaxy_session: Optional[GalaxySession] = None) -> None:
51+
def __init__(
52+
self, sa_session: Union[scoped_session, "SessionlessContext"], galaxy_session: Optional[GalaxySession] = None
53+
) -> None:
5054
self.sa_session = sa_session
5155
# Minimum tag length.
5256
self.min_tag_len = 1
@@ -64,7 +68,10 @@ def __init__(self, sa_session: scoped_session, galaxy_session: Optional[GalaxySe
6468

6569
def create_tag_handler_session(self, galaxy_session: Optional[GalaxySession]):
6670
# Creates a transient tag handler that avoids repeated flushes
67-
return GalaxyTagHandlerSession(self.sa_session, galaxy_session=galaxy_session)
71+
if isinstance(self.sa_session, scoped_session):
72+
return GalaxyTagHandlerSession(self.sa_session, galaxy_session=galaxy_session)
73+
else:
74+
return self
6875

6976
def add_tags_from_list(self, user, item, new_tags_list, flush=True):
7077
new_tags_set = set(new_tags_list)
@@ -327,7 +334,7 @@ def _get_tag(self, tag_name):
327334
def _create_tag_instance(self, tag_name):
328335
# For good performance caller should first check if there's already an appropriate tag
329336
tag = Tag(type=0, name=tag_name)
330-
if not self.sa_session:
337+
if not isinstance(self.sa_session, scoped_session):
331338
return tag
332339
Session = sessionmaker(self.sa_session.bind)
333340
with Session() as separate_session:

test/integration/test_pulsar_embedded_extended_metadata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ def handle_galaxy_config_kwds(cls, config):
3131
"metadata_bam",
3232
"job_properties",
3333
"from_work_dir_glob",
34+
"gx_group_tag",
3435
]
3536
)

0 commit comments

Comments
 (0)