logical values should not be allowed in validation since they should have already been converted to the base type
MODIFY
fastavro/_validation.pyx
fastavro/_validation.pyx
# cython: language_level=3str
-import datetime
-import decimal
import numbers
-from uuid import UUID
try:
from collections.abc import Mapping, Sequence
except ImportError:
@@ -42,12 +39,12 @@ cdef inline bint validate_boolean(datum, schema=None,
cdef inline bint validate_string(datum, schema=None,
str parent_ns='', bint raise_errors=True):
- return is_str(datum) or isinstance(datum, UUID)
+ return is_str(datum)
cdef inline bint validate_bytes(datum, schema=None,
str parent_ns='', bint raise_errors=True):
- return isinstance(datum, (bytes, decimal.Decimal))
+ return isinstance(datum, bytes)
cdef inline bint validate_int(datum, schema=None,
@@ -56,8 +53,6 @@ cdef inline bint validate_int(datum, schema=None,
(isinstance(datum, (int, long, numbers.Integral))
and INT_MIN_VALUE <= datum <= INT_MAX_VALUE
and not isinstance(datum, bool))
- or isinstance(datum, (
- datetime.time, datetime.datetime, datetime.date))
)
@@ -67,7 +62,6 @@ cdef inline bint validate_long(datum, schema=None,
(isinstance(datum, (int, long, numbers.Integral))
and LONG_MIN_VALUE <= datum <= LONG_MAX_VALUE
and not isinstance(datum, bool))
- or isinstance(datum, (datetime.time, datetime.datetime, datetime.date))
)
@@ -84,7 +78,6 @@ cdef inline bint validate_fixed(datum, dict schema,
return (
((isinstance(datum, bytes) or isinstance(datum, bytearray))
and len(datum) == schema['size'])
- or isinstance(datum, decimal.Decimal)
)

MODIFY
fastavro/_validation_py.py
fastavro/_validation_py.py
-import datetime
-import decimal
import numbers
-from uuid import UUID
try:
from collections.abc import Mapping, Sequence
except ImportError:
@@ -50,7 +47,7 @@ def validate_boolean(datum, **kwargs):
def validate_string(datum, **kwargs):
"""
- Check that the data value is string or UUID type, uses
+ Check that the data value is string, uses
six for Python version compatibility.
Parameters
@@ -60,12 +57,12 @@ def validate_string(datum, **kwargs):
kwargs: Any
Unused kwargs
"""
- return is_str(datum) or isinstance(datum, UUID)
+ return is_str(datum)
def validate_bytes(datum, **kwargs):
"""
- Check that the data value is (python bytes type or decimal.Decimal type
+ Check that the data value is python bytes type
Parameters
----------
@@ -74,20 +71,17 @@ def validate_bytes(datum, **kwargs):
kwargs: Any
Unused kwargs
"""
- return isinstance(datum, (bytes, decimal.Decimal))
+ return isinstance(datum, bytes)
def validate_int(datum, **kwargs):
"""
Check that the data value is a non floating
point number with size less that Int32.
- Also support for logicalType timestamp validation with datetime.
Int32 = -2147483648<=datum<=2147483647
- conditional python types
- (int, long, numbers.Integral,
- datetime.time, datetime.datetime, datetime.date)
+ conditional python types: int, long, numbers.Integral
Parameters
----------
@@ -100,9 +94,6 @@ def validate_int(datum, **kwargs):
(isinstance(datum, (int, long, numbers.Integral))
and INT_MIN_VALUE <= datum <= INT_MAX_VALUE
and not isinstance(datum, bool))
- or isinstance(
- datum, (datetime.time, datetime.datetime, datetime.date)
- )
)
@@ -110,13 +101,10 @@ def validate_long(datum, **kwargs):
"""
Check that the data value is a non floating
point number with size less that long64.
- * Also support for logicalType timestamp validation with datetime.
Int64 = -9223372036854775808 <= datum <= 9223372036854775807
- conditional python types
- (int, long, numbers.Integral,
- datetime.time, datetime.datetime, datetime.date)
+ conditional python types: int, long, numbers.Integral
:Parameters
----------
@@ -129,9 +117,6 @@ def validate_long(datum, **kwargs):
(isinstance(datum, (int, long, numbers.Integral))
and LONG_MIN_VALUE <= datum <= LONG_MAX_VALUE
and not isinstance(datum, bool))
- or isinstance(
- datum, (datetime.time, datetime.datetime, datetime.date)
- )
)
@@ -172,7 +157,6 @@ def validate_fixed(datum, schema, **kwargs):
"""
return (
(isinstance(datum, bytes) and len(datum) == schema['size'])
- or (isinstance(datum, decimal.Decimal))
)

MODIFY
tests/test_validation.py
tests/test_validation.py
@@ -9,6 +9,7 @@ from fastavro import parse_schema
import pytest
import numpy as np
import sys
+from datetime import datetime
# In PY2 when you do type(int) you get <type 'type'> but in PY3 you get
# <class 'type'>
@@ -265,6 +266,8 @@ def test_validator_numeric():
(False, 'long'),
(False, 'float'),
(False, 'double'),
+ (datetime(2020, 1, 1), 'int'),
+ (datetime(2020, 1, 1), 'long'),
]:
with pytest.raises(ValidationError):
validate(datum, schema)

logical values should not be allowed in validation since they should have already been converted to the base type