]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
utils: parser/validator: passing of custom values from one first tree to another
authorVasek Sraier <git@vakabus.cz>
Mon, 13 Sep 2021 09:20:21 +0000 (11:20 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Fri, 8 Apr 2022 14:17:52 +0000 (16:17 +0200)
manager/knot_resolver_manager/datamodel/types.py
manager/knot_resolver_manager/utils/data_parser_validator.py

index 9f87e47c0c908e6c468458e15d12807ee5853067..f76b9e3f4c1fcab8108ef3fd9ab8f9fced277c6a 100644 (file)
@@ -44,9 +44,6 @@ class Unit(CustomValueType):
                 f" Please convert the value to string an add a unit - {list(type(self)._units.keys())}",
                 object_path,
             )
-        elif isinstance(source_value, type(self)):
-            self._value_orig = source_value._value_orig
-            self._value = source_value._value
         else:
             raise DataValidationException(
                 f"Unexpected input type for Unit type - {type(source_value)}."
@@ -96,9 +93,7 @@ class TimeUnit(Unit):
 class AnyPath(CustomValueType):
     def __init__(self, source_value: Any, object_path: str = "/") -> None:
         super().__init__(source_value)
-        if isinstance(source_value, AnyPath):
-            self._value = source_value._value
-        elif isinstance(source_value, str):
+        if isinstance(source_value, str):
             self._value: Path = Path(source_value)
         else:
             raise DataValidationException(
index fa3fcbf7320bc9d17fdafad10768d218a1225795..288d5248992f509f029b717bb042050772086257 100644 (file)
@@ -178,8 +178,12 @@ def _validated_object_type(
 
     # CustomValueType subclasses
     elif inspect.isclass(cls) and issubclass(cls, CustomValueType):
-        # no validation performed, the implementation does it in the constuctor
-        return cls(obj, object_path=object_path)
+        if isinstance(obj, cls):
+            # if we already have a custom value type, just pass it through
+            return obj
+        else:
+            # no validation performed, the implementation does it in the constuctor
+            return cls(obj, object_path=object_path)
 
     # nested DataParser subclasses
     elif inspect.isclass(cls) and issubclass(cls, DataParser):