Warn instead of crashing on preexisting wrong data type
authorMichele Tartara <mtartara@google.com>
Mon, 22 Jul 2013 13:00:35 +0000 (15:00 +0200)
committerMichele Tartara <mtartara@google.com>
Mon, 22 Jul 2013 15:42:38 +0000 (17:42 +0200)
Using None in a VTYPE_MAYBE_STRING is wrong, because it cannot really
be serialized to a Haskel Nothing, but given that this can (and does)
influence external components already using None, it is turned to a
warning in order not to break the existing behavior.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>

lib/utils/__init__.py

index 0180fe8..876650f 100644 (file)
@@ -99,7 +99,7 @@ def ForceDictType(target, key_types, allowed_values=None):
     if ktype in (constants.VTYPE_STRING, constants.VTYPE_MAYBE_STRING):
       if target[key] is None and ktype == constants.VTYPE_MAYBE_STRING:
         msg = "'None' is not a valid Maybe value. Use 'VALUE_HS_NOTHING'"
-        raise errors.TypeEnforcementError(msg)
+        logging.warning(msg)
       elif (target[key] == constants.VALUE_HS_NOTHING
             and ktype == constants.VTYPE_MAYBE_STRING):
         pass