Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[21.09] Fix creating tags within sessionless context #13552

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/galaxy/model/store/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ def create_dataset(
primary_data.created_from_basename = created_from_basename

if tag_list:
self.tag_handler.add_tags_from_list(self.job.user, primary_data, tag_list, flush=False)
job = getattr(self, "job", None)
self.tag_handler.add_tags_from_list(job and job.user, primary_data, tag_list, flush=False)

# If match specified a name use otherwise generate one from
# designation.
Expand Down Expand Up @@ -415,7 +416,6 @@ def __init__(self, object_store, export_store, working_directory):
self.object_store = object_store
self.export_store = export_store
self.flush_per_n_datasets = None

self.job_working_directory = working_directory # TODO: rename...

@property
Expand Down Expand Up @@ -626,6 +626,7 @@ def collect_elements_for_history(elements):
ext = fields_match.ext
dbkey = fields_match.dbkey
info = element.get("info", None)
tag_list = element.get("tags")
link_data = discovered_file.match.link_data

# Create new primary dataset
Expand Down Expand Up @@ -654,6 +655,7 @@ def collect_elements_for_history(elements):
filename=discovered_file.path,
extra_files=extra_files,
info=info,
tag_list=tag_list,
link_data=link_data,
primary_data=primary_dataset,
sources=sources,
Expand Down
6 changes: 4 additions & 2 deletions lib/galaxy/model/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,10 @@ def _get_tag(self, tag_name):

def _create_tag_instance(self, 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)
if not self.sa_session:
return tag
Session = sessionmaker(self.sa_session.bind)
with Session() as separate_session:
separate_session.add(tag)
try:
Expand Down Expand Up @@ -424,7 +426,7 @@ def _get_tag(self, tag_name):
return self.created_tags.get(tag_name)

def get_tag_by_name(self, tag_name):
self.created_tags.get(tag_name)
return self.created_tags.get(tag_name)


class CommunityTagHandler(TagHandler):
Expand Down
6 changes: 5 additions & 1 deletion test/unit/test_model_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_model_create_context_persist_hdas():
"dbkey": "hg19",
"name": "my file",
"md5": "e5d21b1ea57fc9a31f8ea0110531bf3d",
"tags": ["name:value"]
}],
}
app = _mock_app(store_by="uuid")
Expand All @@ -37,6 +38,9 @@ def test_model_create_context_persist_hdas():
assert imported_hda.metadata.data_lines == 2
assert len(imported_hda.dataset.hashes) == 1
assert imported_hda.dataset.hashes[0].hash_value == "e5d21b1ea57fc9a31f8ea0110531bf3d"
tags = imported_hda.tags
assert len(tags) == 1
assert tags[0].value == "value"

with open(imported_hda.file_name) as f:
assert f.read().startswith("hello world\n")
Expand Down Expand Up @@ -228,7 +232,7 @@ def _import_directory_to_history(app, target, work_directory):
assert len(import_history.datasets) == 0

import_options = store.ImportOptions(allow_dataset_object_edit=True)
import_model_store = store.get_import_model_store_for_directory(target, app=app, user=u, import_options=import_options)
import_model_store = store.get_import_model_store_for_directory(target, app=app, user=u, import_options=import_options, tag_handler=app.tag_handler.create_tag_handler_session())
with import_model_store.target_history(default_history=import_history):
import_model_store.perform_import(import_history)

Expand Down