diff --git a/lib/galaxy/model/store/discover.py b/lib/galaxy/model/store/discover.py index 3cfd8a19e229..3d4f0d6a985d 100644 --- a/lib/galaxy/model/store/discover.py +++ b/lib/galaxy/model/store/discover.py @@ -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. @@ -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 @@ -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 @@ -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, diff --git a/lib/galaxy/model/tags.py b/lib/galaxy/model/tags.py index 17260ddfbfae..8903b5dbb388 100644 --- a/lib/galaxy/model/tags.py +++ b/lib/galaxy/model/tags.py @@ -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: @@ -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): diff --git a/test/unit/test_model_discovery.py b/test/unit/test_model_discovery.py index 3e595b297885..b202a144eb67 100644 --- a/test/unit/test_model_discovery.py +++ b/test/unit/test_model_discovery.py @@ -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") @@ -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") @@ -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)