Explorar o código

Add check for resource keys in utils.get_unique_option_ids()

Nashwan Azhari %!s(int64=8) %!d(string=hai) anos
pai
achega
e41606fd1b
Modificáronse 1 ficheiros con 4 adicións e 0 borrados
  1. 4 0
      coriolis/utils.py

+ 4 - 0
coriolis/utils.py

@@ -419,6 +419,10 @@ def get_unique_option_ids(resources, id_key="id", name_key="name"):
          others, returns the value of the 'id_key'
          others, returns the value of the 'id_key'
        - else, returns the value of the 'name_key
        - else, returns the value of the 'name_key
     """
     """
+    if not all([name_key in d and id_key in d for d in resources]):
+        raise KeyError(
+            "Some resources are missing the name key '%s' "
+            "or ID key '%s': %s" % (name_key, id_key, resources))
 
 
     name_mappings = {}
     name_mappings = {}
     for resource in resources:
     for resource in resources: