Falsey field examples bypass schema validation
Overview
Field example validation currently runs only when the example is truthy. As a result, incorrect examples such as 0 for a string field or False for an integer field are silently accepted, although the corresponding field reader rejects them. Empty lists and dictionaries can also bypass the type check.
This affects validation of metadata constructed from descriptors; it is not a claim that CSV cell validation is bypassed.
Reproduction
Using Python 3.12 on Windows and the repository at commit 6c7146c07fa0f15b5c1bdc09e73309fb339dfe9a:
from frictionless import Schema
# These descriptors currently construct successfully:
Schema({"fields": [{"name": "label", "type": "string", "example": 0}]})
Schema({"fields": [{"name": "count", "type": "integer", "example": False}]})
Schema({"fields": [{"name": "items", "type": "array", "example": {}}]})
For comparison, a truthy invalid example raises FrictionlessException:
Schema({"fields": [{"name": "count", "type": "integer", "example": "invalid"}]})
Expected behavior
Present, non-null examples should be validated regardless of their truth value. Valid examples such as integer 0, boolean False, array [], and object {} should continue to work, as should absent/null examples and the existing default missing-value handling.
Cause and scope
Field.metadata_validate uses if example: before constructing a field and calling read_cell. Checking example is not None instead preserves the existing field-reader behavior while covering falsey values.
The independent in-memory reproduction covered eight invalid falsey examples and eight valid falsey/null examples. All eight invalid cases were incorrectly accepted before the fix. No network requests or external data-service writes are needed to reproduce it.