Repository: frictionlessdata/frictionless-py

Issue:
Package/resource doesn't catch an error if `schema.fields[].format = {}`
# Overview

It should be a string but JSON schema validation is silent if it's a dict, for example.

Discussion:

Patch:
diff --git a/frictionless/assets/profiles/resource/tabular.json b/frictionless/assets/profiles/resource/tabular.json
index b3213554..3d7295bf 100644
--- a/frictionless/assets/profiles/resource/tabular.json
+++ b/frictionless/assets/profiles/resource/tabular.json
@@ -931,6 +931,13 @@
                       "boolean"
                     ]
                   },
+                  "format": {
+                    "description": "There are no format keyword options for `boolean`: only `default` is allowed.",
+                    "enum": [
+                      "default"
+                    ],
+                    "default": "default"
+                  },
                   "trueValues": {
                     "type": "array",
                     "minItems": 1,
diff --git a/frictionless/assets/profiles/schema.json b/frictionless/assets/profiles/schema.json
index 3a9e4ae3..d3e37582 100644
--- a/frictionless/assets/profiles/schema.json
+++ b/frictionless/assets/profiles/schema.json
@@ -819,6 +819,13 @@
                   "boolean"
                 ]
               },
+              "format": {
+                "description": "There are no format keyword options for `boolean`: only `default` is allowed.",
+                "enum": [
+                  "default"
+                ],
+                "default": "default"
+              },
               "trueValues": {
                 "type": "array",
                 "minItems": 1,


Test patch:
diff --git a/tests/test_resource.py b/tests/test_resource.py
index beb2e652..554376c6 100644
--- a/tests/test_resource.py
+++ b/tests/test_resource.py
@@ -2,7 +2,8 @@ import os
 import json
 import yaml
 import pytest
-from frictionless import Resource, Query, FrictionlessException, describe_resource
+from frictionless import Resource, Schema, Field, Query, describe_resource
+from frictionless import FrictionlessException
 
 
 # General
@@ -910,6 +911,24 @@ def test_resource_to_table_respect_query_issue_503():
         assert table.read_rows() == [{"id": 1, "name": "english"}]
 
 
+# Metadata
+
+
+def test_resource_metadata_bad_schema_format():
+    schema = Schema(
+        fields=[
+            Field(
+                name="name",
+                type="boolean",
+                format={"trueValues": "Yes", "falseValues": "No"},
+            )
+        ]
+    )
+    resource = Resource(name="name", path="data/table.csv", schema=schema)
+    assert resource.metadata_valid is False
+    assert resource.metadata_errors[0].code == "field-error"
+
+
 # Multipart
 
 
diff --git a/tests/test_schema.py b/tests/test_schema.py
index f3437f6c..70eaa245 100644
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -4,7 +4,7 @@ import yaml
 import pytest
 import requests
 from decimal import Decimal
-from frictionless import Schema, FrictionlessException, describe_schema
+from frictionless import Schema, Field, FrictionlessException, describe_schema
 
 
 # General
@@ -372,6 +372,23 @@ def test_schema_to_yaml(tmpdir):
         assert schema == yaml.safe_load(file)
 
 
+# Metadata
+
+
+def test_schema_metadata_bad_schema_format():
+    schema = Schema(
+        fields=[
+            Field(
+                name="name",
+                type="boolean",
+                format={"trueValues": "Yes", "falseValues": "No"},
+            )
+        ]
+    )
+    assert schema.metadata_valid is False
+    assert schema.metadata_errors[0].code == "field-error"
+
+
 # Issues