Bug 1390983 - Keyed-by default shouldn't be the only item, error out if it is. r=dustin draft
authorJustin Wood <Callek@gmail.com>
Wed, 16 Aug 2017 13:48:46 -0400
changeset 647656 3cd4312e64394f790a7a15fd19b9c8a900bcbe82
parent 647655 a6269aaf2eb5d17e61e0e9808334611330503965
child 726588 af39a25d16057023c40c0a62f04634574364c2b0
push id74493
push userCallek@gmail.com
push dateWed, 16 Aug 2017 18:00:24 +0000
reviewersdustin
bugs1390983
milestone57.0a1
Bug 1390983 - Keyed-by default shouldn't be the only item, error out if it is. r=dustin MozReview-Commit-ID: 6AKU4iakl3s
taskcluster/taskgraph/util/schema.py
--- a/taskcluster/taskgraph/util/schema.py
+++ b/taskcluster/taskgraph/util/schema.py
@@ -110,16 +110,24 @@ def resolve_keyed_by(item, field, item_n
     while True:
         if not isinstance(value, dict) or len(value) != 1 or not value.keys()[0].startswith('by-'):
             return item
 
         keyed_by = value.keys()[0][3:]  # strip off 'by-' prefix
         key = extra_values.get(keyed_by) if keyed_by in extra_values else item[keyed_by]
         alternatives = value.values()[0]
 
+        if len(alternatives) == 1 and 'default' in alternatives:
+            # Error out when only 'default' is specified as only alternatives,
+            # because we don't need to by-{keyed_by} there.
+            raise Exception(
+                "Keyed-by '{}' unnecessary with only value 'default' "
+                "found, when determining item '{}' in '{}'".format(
+                    keyed_by, field, item_name))
+
         matches = keymatch(alternatives, key)
         if len(matches) > 1:
             raise Exception(
                 "Multiple matching values for {} {!r} found while "
                 "determining item {} in {}".format(
                     keyed_by, key, field, item_name))
         elif matches:
             value = container[subfield] = matches[0]