fix type error in cython implementation
MODIFY
fastavro/_logical_writers.pyx
fastavro/_logical_writers.pyx
@@ -29,7 +29,7 @@ cdef long64 MLS_PER_HOUR = const.MLS_PER_HOUR
cdef has_timestamp_fn = hasattr(datetime.datetime, 'timestamp')
-cpdef long64 prepare_timestamp_millis(object data, schema):
+cpdef prepare_timestamp_millis(object data, schema):
cdef object tt
cdef tm time_tuple
if isinstance(data, datetime.datetime):
@@ -55,7 +55,7 @@ cpdef long64 prepare_timestamp_millis(object data, schema):
return data
-cpdef long64 prepare_timestamp_micros(object data, schema):
+cpdef prepare_timestamp_micros(object data, schema):
cdef object tt
cdef tm time_tuple
if isinstance(data, datetime.datetime):

MODIFY
tests/conftest.py
tests/conftest.py
@@ -6,6 +6,16 @@ from fastavro._schema_common import SCHEMA_DEFS
from fastavro._timezone import utc
+@pytest.fixture(scope="function", autouse=True)
+def look_for_cython_error(capfd):
+ """If an exception happens in cython and we don't handle it properly it
+ will usually print a message to stderr saying that an exception was
+ ignored. Here we check for that in every test function."""
+ yield
+ captured = capfd.readouterr()
+ assert "Exception ignored" not in captured.err
+
+
@pytest.fixture(scope='function')
def clean_schemas():
schema_keys = {key for key in SCHEMA_DEFS.keys()}

MODIFY
tests/test_validation.py
tests/test_validation.py
@@ -270,6 +270,21 @@ def test_validator_numeric():
pytest.fail("{} should not validate as {}".format(datum, schema))
+def test_validator_logical():
+ """https://github.com/fastavro/fastavro/issues/365"""
+ for datum, schema in [
+ (1, {"type": "long", "logicalType": "timestamp-micros"}),
+ ]:
+ validate(datum, schema)
+
+ for datum, schema in [
+ ("foo", {"type": "long", "logicalType": "timestamp-micros"}),
+ ]:
+ with pytest.raises(ValidationError):
+ validate(datum, schema)
+ pytest.fail("{} should not validate as {}".format(datum, schema))
+
+
def test_validate_array():
my_schema = {
"fields": [

fix type error in cython implementation