arrays should only validate against sequences, not iterables
MODIFY
fastavro/_validation.pyx
fastavro/_validation.pyx
import datetime
import decimal
import numbers
-from collections import Iterable, Mapping
+from collections import Mapping, Sequence
from . import const
from ._six import long, is_str, iterkeys, itervalues
@@ -83,7 +83,7 @@ cdef inline bint validate_enum(datum, dict schema,
cdef inline bint validate_array(datum, dict schema,
str parent_ns='', bint raise_errors=True) except -1:
- if not isinstance(datum, Iterable) or is_str(datum):
+ if not isinstance(datum, Sequence) or is_str(datum):
return False
for d in datum:

MODIFY
fastavro/_validation_py.py
fastavro/_validation_py.py
import datetime
import decimal
import numbers
-from collections import Iterable, Mapping
+from collections import Mapping, Sequence
from fastavro.const import (
INT_MAX_VALUE, INT_MIN_VALUE, LONG_MAX_VALUE, LONG_MIN_VALUE
@@ -199,7 +199,7 @@ def validate_array(datum, schema, parent_ns=None, raise_errors=True):
If true, raises ValidationError on invalid data
"""
return (
- isinstance(datum, Iterable) and
+ isinstance(datum, Sequence) and
not is_str(datum) and
all(validate(datum=d, schema=schema['items'],
field=parent_ns,

MODIFY
tests/test_fastavro.py
tests/test_fastavro.py
@@ -1720,3 +1720,31 @@ def test_user_specified_sync():
fastavro.writer(file2, schema, records, sync_marker=b'sync')
assert file1.getvalue() == file2.getvalue()
+
+
+def test_order_of_values_in_map():
+ """https://github.com/fastavro/fastavro/issues/303"""
+ schema = {
+ 'doc': 'A weather reading.',
+ 'name': 'Weather',
+ 'namespace': 'test',
+ 'type': 'record',
+ 'fields': [{
+ 'name': 'metadata',
+ 'type': {
+ 'type': 'map',
+ 'values': [{
+ 'type': 'array',
+ 'items': 'string'
+ }, {
+ 'type': 'map',
+ 'values': ['string']
+ }]
+ }
+ }],
+ }
+ parsed_schema = fastavro.parse_schema(schema)
+
+ records = [{'metadata': {'map1': {'map2': 'str'}}}]
+
+ assert records == roundtrip(parsed_schema, records)

arrays should only validate against sequences, not iterables