]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
modeling/base_schema.py: empty lists not allowed
authorAleš Mrázek <ales.mrazek@nic.cz>
Mon, 28 Aug 2023 13:11:07 +0000 (15:11 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 4 Sep 2023 08:58:11 +0000 (10:58 +0200)
manager/knot_resolver_manager/utils/modeling/base_schema.py
manager/tests/unit/utils/modeling/test_base_schema.py

index 14c97d2f9dfaa695704f970ac25efb41255c379d..b9b584c3cfaa3ae3c8041ff951f1a12334974935 100644 (file)
@@ -294,6 +294,8 @@ class ObjectMapper:
         try:
             for i, val in enumerate(obj):
                 res.append(self.map_object(inner_type, val, object_path=f"{object_path}[{i}]"))
+            if len(res) == 0:
+                raise DataValidationError("empty list is not allowed", object_path)
         except DataValidationError as e:
             errs.append(e)
         except TypeError as e:
index ca41572d1de4c5b92a5860c70fe1bc7c5c363292..07e278bbc8d8570faee6b977de50e5af7867cc66 100644 (file)
@@ -53,6 +53,14 @@ def test_parsing_str_invalid():
         _TestStr(parse_yaml("v: false"))  # bool
 
 
+def test_parsing_list_empty():
+    class ListSchema(ConfigSchema):
+        empty: List[Any]
+
+    with raises(DataValidationError):
+        ListSchema(parse_yaml("empty: []"))
+
+
 @pytest.mark.parametrize("typ,val", [(_TestInt, 5), (_TestBool, False), (_TestStr, "test")])
 def test_parsing_nested(typ: Type[ConfigSchema], val: Any):
     class UpperSchema(ConfigSchema):