]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
utils: modelling: replace '_' with '-' in dict key
authorAleš <ales.mrazek@nic.cz>
Wed, 1 Dec 2021 14:43:59 +0000 (15:43 +0100)
committerAleš Mrázek <ales.mrazek@nic.cz>
Fri, 8 Apr 2022 14:17:53 +0000 (16:17 +0200)
- ParsedTree is replacing '-' with '_' which is undesirable
- Dict keys are change to original during validation

manager/knot_resolver_manager/datamodel/templates/stub_zones.lua.j2
manager/knot_resolver_manager/utils/modelling.py

index 000d9e632d2cf6c6c3d4bb7e6bd552a721cec402..68095706604f73a9911a4d0ecf0ca42ecd265ebc 100644 (file)
@@ -5,7 +5,7 @@
 {% if stub.views %}
 {% for view_id in stub.views %}
 -- stub-zone: {{ name }} view: {{ view_id }}
-{% set view = cfg.views[view_id.replace("-", "_")] %}
+{% set view = cfg.views[view_id] %}
 
 {% set options = none %}
 {% if stub.options and view.options %}
index ddc5adb1eee2ad4d300ee914130d66d89ef4cd5c..e86f1f6e61a98a289f368272041bea127f7bd2fd 100644 (file)
@@ -278,12 +278,14 @@ def _validated_object_type(
     elif is_dict(cls):
         key_type, val_type = get_generic_type_arguments(cls)
         try:
-            return {
-                _validated_object_type(key_type, key, object_path=f"{object_path} @ key {key}"): _validated_object_type(
-                    val_type, val, object_path=f"{object_path} @ value for key {key}"
+            d: Dict[Any, Any] = {}
+            for key, val in obj.items():
+                k: str = str(key).replace("_", "-")
+
+                d[_validated_object_type(key_type, k, object_path=f"{object_path} @ key {k}")] = _validated_object_type(
+                    val_type, val, object_path=f"{object_path} @ value for key {k}"
                 )
-                for key, val in obj.items()
-            }
+            return d
         except AttributeError as e:
             raise SchemaException(
                 f"Expected dict-like object, but failed to access its .items() method. Value was {obj}", object_path