Commit 35162ef0 authored by mvdbeek's avatar mvdbeek
Browse files

Iterate over param_dict only once

This should fix https://github.com/galaxyproject/galaxy/issues/12179.
Ideally we wouldn't have to do this at all, we should be able to hide
this behind a profile flag. For regular tools this is a fallback for
referencing datasets without prefix.
parent a87405cb
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -272,17 +272,17 @@ class ToolEvaluator:
        # - Only necessary when self.check_values is False (==external dataset
        #   tool?: can this be abstracted out as part of being a datasouce tool?)
        # For now we try to not wrap unnecessarily, but this should be untangled at some point.
        matches = None
        for name, data in input_datasets.items():
            param_dict_value = param_dict.get(name, None)
            if data and param_dict_value is None:
                # We may have a nested parameter that is not fully prefixed.
                # We try recovering from param_dict, but tool authors should really use fully-qualified
                # variables
                wrappers = find_instance_nested(param_dict,
                                                instances=(DatasetFilenameWrapper, DatasetListWrapper),
                                                match_key=name)
                if len(wrappers) == 1:
                    wrapper = wrappers[0]
                if matches is None:
                    matches = find_instance_nested(param_dict, instances=(DatasetFilenameWrapper, DatasetListWrapper))
                wrapper = matches.get(name)
                if wrapper:
                    param_dict[name] = wrapper
                    continue
            if not isinstance(param_dict_value, (DatasetFilenameWrapper, DatasetListWrapper)):
+7 −6
Original line number Diff line number Diff line
@@ -621,20 +621,21 @@ def sanitize_for_filename(text, default=None):
    return out


def find_instance_nested(item, instances, match_key=None):
def find_instance_nested(item, instances):
    """
    Recursively find instances from lists, dicts, tuples.

    `instances` should be a tuple of valid instances
    If match_key is given the key must match for an instance to be added to the list of found instances.
    `instances` should be a tuple of valid instances.
    Returns a dictionary, where keys are the deepest key at which an instance has been found,
    and the value is the matched instance.
    """

    matches = []
    matches = {}

    def visit(path, key, value):
        if isinstance(value, instances):
            if match_key is None or match_key == key:
                matches.append(value)
            if key not in matches:
                matches[key] = value
        return key, value

    def enter(path, key, value):