18574: Fixes bug for keys without values.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Wed, 2 Mar 2022 18:22:28 +0000 (15:22 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Wed, 2 Mar 2022 18:22:28 +0000 (15:22 -0300)
It turns out that:

{}.get('something', {}) != {'something':None}.get('something', {})

...and when there's no values member on any given vocabulary key, the
controller fill it with null, so we have to handle the explicit case
of having {value: None} on the exported vocabulary.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

sdk/python/arvados/vocabulary.py
sdk/python/tests/test_vocabulary.py

index ae03ef42db7c0349eff35ea3d627f0873b4a8489..89698e20afc49c4c058d4858e418320dcb189080 100644 (file)
@@ -20,11 +20,11 @@ class Vocabulary(object):
         self.strict_keys = voc_definition.get('strict_tags', False)
         self.key_aliases = {}
 
-        for key_id, val in voc_definition.get('tags', {}).items():
+        for key_id, val in (voc_definition.get('tags') or {}).items():
             strict = val.get('strict', False)
             key_labels = [l['label'] for l in val.get('labels', [])]
             values = {}
-            for v_id, v_val in val.get('values', {}).items():
+            for v_id, v_val in (val.get('values') or {}).items():
                 labels = [l['label'] for l in v_val.get('labels', [])]
                 values[v_id] = VocabularyValue(v_id, labels)
             vk = VocabularyKey(key_id, key_labels, values, strict)
index 56647e82432d97bf21307263f0a13fe670bc1518..cce2ec62338f28f5bdfa6128e7a9da8f392ace97 100644 (file)
@@ -65,6 +65,7 @@ class VocabularyTest(unittest.TestCase):
                     {'label': 'Comment'},
                     {'label': 'Notes'},
                 ],
+                'values': None,
             },
         },
     }