From ca5132d7bf5165877dfbed873a89bbe7b1a5f5c5 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Thu, 26 Oct 2023 15:43:18 +0200 Subject: [PATCH 1/2] Skip change_datatype things if we're not actually changing the extension Side-steps a problem with FileParameter in the most efficient way possible. This likely became a problem for one of Wolfgang's workflow afer we dropped some earlier unnecessary flushes. --- lib/galaxy/datatypes/registry.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/galaxy/datatypes/registry.py b/lib/galaxy/datatypes/registry.py index 8c14bb64d8d5..ce5f9ad890e5 100644 --- a/lib/galaxy/datatypes/registry.py +++ b/lib/galaxy/datatypes/registry.py @@ -590,13 +590,14 @@ def get_datatype_by_extension(self, ext): return self.datatypes_by_extension.get(ext, None) def change_datatype(self, data, ext): - data.extension = ext - # call init_meta and copy metadata from itself. The datatype - # being converted *to* will handle any metadata copying and - # initialization. - if data.has_data(): - data.set_size() - data.init_meta(copy_from=data) + if data.extension != ext: + data.extension = ext + # call init_meta and copy metadata from itself. The datatype + # being converted *to* will handle any metadata copying and + # initialization. + if data.has_data(): + data.set_size() + data.init_meta(copy_from=data) return data def load_datatype_converters(self, toolbox, use_cached=False): From d7beda0f1acf2fc923f4389fad3cc9fb049b7afe Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Thu, 26 Oct 2023 16:44:48 +0200 Subject: [PATCH 2/2] Commit if we've got outstanding MetadataFile instances --- lib/galaxy/model/metadata.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/model/metadata.py b/lib/galaxy/model/metadata.py index ed757314edca..a0b53a1527ae 100644 --- a/lib/galaxy/model/metadata.py +++ b/lib/galaxy/model/metadata.py @@ -604,7 +604,16 @@ def wrap(self, value, session): if isinstance(value, int): return session.query(galaxy.model.MetadataFile).get(value) else: - return session.query(galaxy.model.MetadataFile).filter_by(uuid=value).one() + wrapped_value = session.query(galaxy.model.MetadataFile).filter_by(uuid=value).one_or_none() + if wrapped_value: + return wrapped_value + else: + # If we've simultaneously copied the dataset and we've changed the datatype on the + # copy we may not have committed the MetadataFile yet, so we need to commit the session. + # TODO: It would be great if we can avoid the commit in the future. + with transaction(session): + session.commit() + return session.query(galaxy.model.MetadataFile).filter_by(uuid=value).one_or_none() def make_copy(self, value, target_context: MetadataCollection, source_context): session = target_context._object_session(target_context.parent)