Stronger type checking for provided_metadata.

This commit is contained in:
John Chilton
2022-08-25 12:26:18 -04:00
parent df7fcb0283
commit bd9c8314ed
2 changed files with 8 additions and 10 deletions
+8 -8
View File
@@ -103,8 +103,8 @@ class LegacyToolProvidedMetadata(BaseToolProvidedMetadata):
with open(meta_file) as f:
for line in f:
try:
line = stringify_dictionary_keys(json.loads(line))
assert "type" in line
line_as_dict = stringify_dictionary_keys(json.loads(line))
assert "type" in line_as_dict
except Exception as e:
message = f'Got JSON data from tool, but line is improperly formatted or no "type" key in: [{line}]'
raise ValueError(message) from e
@@ -112,12 +112,12 @@ class LegacyToolProvidedMetadata(BaseToolProvidedMetadata):
# This isn't insecure. We loop the job's output datasets in
# the finish method, so if a tool writes out metadata for a
# dataset id that it doesn't own, it'll just be ignored.
dataset_id_not_specified = line["type"] == "dataset" and "dataset_id" not in line
dataset_id_not_specified = line_as_dict["type"] == "dataset" and "dataset_id" not in line_as_dict
if dataset_id_not_specified:
dataset_basename = line["dataset"]
dataset_basename = line_as_dict["dataset"]
if job_wrapper:
try:
line["dataset_id"] = job_wrapper.job_io.get_output_file_id(dataset_basename)
line_as_dict["dataset_id"] = job_wrapper.job_io.get_output_file_id(dataset_basename)
except KeyError:
log.warning(
f"({job_wrapper.job_id}) Tool provided job dataset-specific metadata without specifying a dataset"
@@ -131,11 +131,11 @@ class LegacyToolProvidedMetadata(BaseToolProvidedMetadata):
)
dataset_id = match.group(2)
if dataset_id.isdigit():
line["dataset_id"] = dataset_id
line_as_dict["dataset_id"] = dataset_id
else:
line["dataset_uuid"] = dataset_id
line_as_dict["dataset_uuid"] = dataset_id
self.tool_provided_job_metadata.append(line)
self.tool_provided_job_metadata.append(line_as_dict)
def get_dataset_meta(self, output_name, dataset_id, dataset_uuid):
for meta in self.tool_provided_job_metadata:
-2
View File
@@ -161,8 +161,6 @@ check_untyped_defs = False
check_untyped_defs = False
[mypy-galaxy.tools.bundled.filters.join]
check_untyped_defs = False
[mypy-galaxy.tool_util.provided_metadata]
check_untyped_defs = False
[mypy-galaxy.tool_util.output_checker]
check_untyped_defs = False
[mypy-galaxy.tool_util.verify.test_data]