no need to force parsing the schema on validate; it will get parsed if needed
MODIFY
fastavro/_validation.pyx
fastavro/_validation.pyx
@@ -259,9 +259,7 @@ cpdef _validate(
cpdef validate(object datum, object schema, str field="",
bint raise_errors=True):
named_schemas = {}
- parsed_schema = parse_schema(
- schema, _force=True, _named_schemas=named_schemas
- )
+ parsed_schema = parse_schema(schema, _named_schemas=named_schemas)
return _validate(datum, parsed_schema, named_schemas, field, raise_errors)
@@ -270,9 +268,7 @@ cpdef validate_many(records, schema, bint raise_errors=True):
cdef list errors = []
cdef list results = []
named_schemas = {}
- parsed_schema = parse_schema(
- schema, _force=True, _named_schemas=named_schemas
- )
+ parsed_schema = parse_schema(schema, _named_schemas=named_schemas)
for record in records:
try:
result = _validate(

MODIFY
fastavro/_validation_py.py
fastavro/_validation_py.py
@@ -393,7 +393,7 @@ def validate(datum, schema, field=None, raise_errors=True):
validate(record, schema)
"""
named_schemas = {}
- parsed_schema = parse_schema(schema, _force=True, _named_schemas=named_schemas)
+ parsed_schema = parse_schema(schema, _named_schemas=named_schemas)
return _validate(datum, parsed_schema, named_schemas, field, raise_errors)
@@ -420,7 +420,7 @@ def validate_many(records, schema, raise_errors=True):
validate_many(records, schema)
"""
named_schemas = {}
- parsed_schema = parse_schema(schema, _force=True, _named_schemas=named_schemas)
+ parsed_schema = parse_schema(schema, _named_schemas=named_schemas)
errors = []
results = []
for record in records:

MODIFY
tests/test_validation.py
tests/test_validation.py
@@ -574,3 +574,21 @@ def test_record_name_with_named_type_in_union():
parsed_schema = parse_schema(schema)
validate_many(records, parsed_schema)
+
+
+def test_validate_should_not_parse_schema_if_it_was_parsed_already():
+ named_schemas = {}
+ parse_schema(
+ {"name": "B", "type": "record", "fields": [{"name": "bar", "type": "string"}]},
+ _named_schemas=named_schemas,
+ )
+
+ a_schema = parse_schema(
+ {"name": "A", "type": "record", "fields": [{"name": "b", "type": "B"}]},
+ _named_schemas=named_schemas,
+ )
+
+ records = [{"b": {"bar": "bar"}}]
+
+ validate_many(records, a_schema)
+ validate(records[0], a_schema)

no need to force parsing the schema on validate; it will get parsed if needed