ensure records have a name field
MODIFY
fastavro/_schema.pyx
fastavro/_schema.pyx
@@ -68,9 +68,6 @@ def extract_named_schemas_into_repo(schema, repo, transformer, parent_ns=None):
namespace, name = schema_name(schema, parent_ns)
- if name:
- repo[name] = transformer(schema)
-
schema_type = schema.get('type')
if schema_type == 'array':
namespaced_name = extract_named_schemas_into_repo(
@@ -82,7 +79,7 @@ def extract_named_schemas_into_repo(schema, repo, transformer, parent_ns=None):
if namespaced_name:
schema['items'] = namespaced_name
return
- if schema_type == 'map':
+ elif schema_type == 'map':
namespaced_name = extract_named_schemas_into_repo(
schema['values'],
repo,
@@ -92,7 +89,17 @@ def extract_named_schemas_into_repo(schema, repo, transformer, parent_ns=None):
if namespaced_name:
schema['values'] = namespaced_name
return
- # Normal record.
+ else:
+ # dict-y type schema
+ if name:
+ repo[name] = transformer(schema)
+ elif schema_type == 'record':
+ msg = (
+ '"name" is a required field missing from ' +
+ 'the schema: {}'.format(schema)
+ )
+ raise Exception(msg)
+
for field in schema.get('fields', []):
namespaced_name = extract_named_schemas_into_repo(
field['type'],

MODIFY
fastavro/_schema_py.py
fastavro/_schema_py.py
@@ -67,9 +67,6 @@ def extract_named_schemas_into_repo(schema, repo, transformer, parent_ns=None):
namespace, name = schema_name(schema, parent_ns)
- if name:
- repo[name] = transformer(schema)
-
schema_type = schema.get('type')
if schema_type == 'array':
namespaced_name = extract_named_schemas_into_repo(
@@ -81,7 +78,7 @@ def extract_named_schemas_into_repo(schema, repo, transformer, parent_ns=None):
if namespaced_name:
schema['items'] = namespaced_name
return
- if schema_type == 'map':
+ elif schema_type == 'map':
namespaced_name = extract_named_schemas_into_repo(
schema['values'],
repo,
@@ -91,7 +88,17 @@ def extract_named_schemas_into_repo(schema, repo, transformer, parent_ns=None):
if namespaced_name:
schema['values'] = namespaced_name
return
- # Normal record.
+ else:
+ # dict-y type schema
+ if name:
+ repo[name] = transformer(schema)
+ elif schema_type == 'record':
+ msg = (
+ '"name" is a required field missing from ' +
+ 'the schema: {}'.format(schema)
+ )
+ raise Exception(msg)
+
for field in schema.get('fields', []):
namespaced_name = extract_named_schemas_into_repo(
field['type'],

MODIFY
tests/test_aliases.py
tests/test_aliases.py
@@ -7,6 +7,7 @@ import pytest
def test_aliases_not_present():
schema = {
"type": "record",
+ "name": "test_aliases_not_present",
"fields": [{
"name": "test",
"type": "double"
@@ -15,6 +16,7 @@ def test_aliases_not_present():
new_schema = {
"type": "record",
+ "name": "test_aliases_not_present_new",
"fields": [
{"name": "newtest", "type": "double", "aliases": ["testX"]},
]
@@ -32,6 +34,7 @@ def test_aliases_not_present():
def test_incompatible_aliases():
schema = {
"type": "record",
+ "name": "test_incompatible_aliases",
"fields": [{
"name": "test",
"type": "double"
@@ -40,6 +43,7 @@ def test_incompatible_aliases():
new_schema = {
"type": "record",
+ "name": "test_incompatible_aliases_new",
"fields": [
{"name": "newtest", "type": "int", "aliases": ["test"]},
]
@@ -57,6 +61,7 @@ def test_incompatible_aliases():
def test_aliases_in_reader_schema():
schema = {
"type": "record",
+ "name": "test_aliases_in_reader_schema",
"fields": [{
"name": "test",
"type": "int"
@@ -65,6 +70,7 @@ def test_aliases_in_reader_schema():
new_schema = {
"type": "record",
+ "name": "test_aliases_in_reader_schema_new",
"fields": [{
"name": "newtest",
"type": "int",

MODIFY
tests/test_complex.py
tests/test_complex.py
@@ -39,6 +39,7 @@ schema = {
"name": "array_record",
"type": {"type": "array", "items": {
"type": "record",
+ "name": "some_record",
"fields": [
{
"name": "f1",

MODIFY
tests/test_fastavro.py
tests/test_fastavro.py
@@ -104,6 +104,7 @@ def test_acquaint_schema_rejects_undleclared_name():
try:
fastavro.schema.acquaint_schema({
"type": "record",
+ "name": "test_acquaint_schema_rejects_undleclared_name",
"fields": [{
"name": "left",
"type": "Thinger",
@@ -118,6 +119,7 @@ def test_acquaint_schema_rejects_unordered_references():
try:
fastavro.schema.acquaint_schema({
"type": "record",
+ "name": "test_acquaint_schema_rejects_unordered_references",
"fields": [{
"name": "left",
"type": "Thinger"
@@ -213,7 +215,8 @@ def test_acquaint_schema_accepts_nested_records_from_arrays():
"name": "single"
}
],
- "type": "record"
+ "type": "record",
+ "name": "test_acquaint_schema_accepts_nested_records_from_arrays",
})
assert 'Nested' in fastavro.write.SCHEMA_DEFS
@@ -257,6 +260,7 @@ def test_missing_schema():
def test_default_values():
schema = {
"type": "record",
+ "name": "test_default_values",
"fields": [{
"name": "default_field",
"type": "string",
@@ -272,6 +276,7 @@ def test_default_values():
def test_nullable_values():
schema = {
"type": "record",
+ "name": "test_nullable_values",
"fields": [{
"name": "nullable_field",
"type": ["string", "null"]
@@ -291,6 +296,7 @@ def test_nullable_values():
def test_metadata():
schema = {
"type": "record",
+ "name": "test_metadata",
"fields": []
}
@@ -390,6 +396,7 @@ def test_repo_caching_issue():
def test_schema_migration_remove_field():
schema = {
"type": "record",
+ "name": "test_schema_migration_remove_field",
"fields": [{
"name": "test",
"type": "string",
@@ -398,6 +405,7 @@ def test_schema_migration_remove_field():
new_schema = {
"type": "record",
+ "name": "test_schema_migration_remove_field_new",
"fields": []
}
@@ -413,11 +421,13 @@ def test_schema_migration_remove_field():
def test_schema_migration_add_default_field():
schema = {
"type": "record",
+ "name": "test_schema_migration_add_default_field",
"fields": []
}
new_schema = {
"type": "record",
+ "name": "test_schema_migration_add_default_field_new",
"fields": [{
"name": "test",
"type": "string",
@@ -437,6 +447,7 @@ def test_schema_migration_add_default_field():
def test_schema_migration_type_promotion():
schema = {
"type": "record",
+ "name": "test_schema_migration_type_promotion",
"fields": [{
"name": "test",
"type": ["string", "int"],
@@ -445,6 +456,7 @@ def test_schema_migration_type_promotion():
new_schema = {
"type": "record",
+ "name": "test_schema_migration_type_promotion_new",
"fields": [{
"name": "test",
"type": ["float", "string"],
@@ -463,6 +475,7 @@ def test_schema_migration_type_promotion():
def test_schema_migration_maps_with_union_promotion():
schema = {
"type": "record",
+ "name": "test_schema_migration_maps_with_union_promotion",
"fields": [{
"name": "test",
"type": {
@@ -474,6 +487,7 @@ def test_schema_migration_maps_with_union_promotion():
new_schema = {
"type": "record",
+ "name": "test_schema_migration_maps_with_union_promotion_new",
"fields": [{
"name": "test",
"type": {
@@ -495,6 +509,7 @@ def test_schema_migration_maps_with_union_promotion():
def test_schema_migration_array_with_union_promotion():
schema = {
"type": "record",
+ "name": "test_schema_migration_array_with_union_promotion",
"fields": [{
"name": "test",
"type": {
@@ -506,6 +521,7 @@ def test_schema_migration_array_with_union_promotion():
new_schema = {
"type": "record",
+ "name": "test_schema_migration_array_with_union_promotion_new",
"fields": [{
"name": "test",
"type": {
@@ -527,6 +543,7 @@ def test_schema_migration_array_with_union_promotion():
def test_schema_migration_writer_union():
schema = {
"type": "record",
+ "name": "test_schema_migration_writer_union",
"fields": [{
"name": "test",
"type": ["string", "int"]
@@ -535,6 +552,7 @@ def test_schema_migration_writer_union():
new_schema = {
"type": "record",
+ "name": "test_schema_migration_writer_union_new",
"fields": [{
"name": "test",
"type": "int"
@@ -553,6 +571,7 @@ def test_schema_migration_writer_union():
def test_schema_migration_reader_union():
schema = {
"type": "record",
+ "name": "test_schema_migration_reader_union",
"fields": [{
"name": "test",
"type": "int"
@@ -561,6 +580,7 @@ def test_schema_migration_reader_union():
new_schema = {
"type": "record",
+ "name": "test_schema_migration_reader_union_new",
"fields": [{
"name": "test",
"type": ["string", "int"]
@@ -579,6 +599,7 @@ def test_schema_migration_reader_union():
def test_schema_migration_union_failure():
schema = {
"type": "record",
+ "name": "test_schema_migration_union_failure",
"fields": [{
"name": "test",
"type": "boolean"
@@ -587,6 +608,7 @@ def test_schema_migration_union_failure():
new_schema = {
"type": "record",
+ "name": "test_schema_migration_union_failure_new",
"fields": [{
"name": "test",
"type": ["string", "int"]
@@ -606,6 +628,7 @@ def test_schema_migration_union_failure():
def test_schema_migration_array_failure():
schema = {
"type": "record",
+ "name": "test_schema_migration_array_failure",
"fields": [{
"name": "test",
"type": {
@@ -617,6 +640,7 @@ def test_schema_migration_array_failure():
new_schema = {
"type": "record",
+ "name": "test_schema_migration_array_failure_new",
"fields": [{
"name": "test",
"type": {
@@ -639,6 +663,7 @@ def test_schema_migration_array_failure():
def test_schema_migration_maps_failure():
schema = {
"type": "record",
+ "name": "test_schema_migration_maps_failure",
"fields": [{
"name": "test",
"type": {
@@ -650,6 +675,7 @@ def test_schema_migration_maps_failure():
new_schema = {
"type": "record",
+ "name": "test_schema_migration_maps_failure_new",
"fields": [{
"name": "test",
"type": {
@@ -693,6 +719,7 @@ def test_schema_migration_enum_failure():
def test_schema_migration_schema_mismatch():
schema = {
"type": "record",
+ "name": "test_schema_migration_schema_mismatch",
"fields": [{
"name": "test",
"type": "string",
@@ -1070,6 +1097,7 @@ def test_ordered_dict_map():
"""
schema = {
"type": "record",
+ "name": "test_ordered_dict_map",
"fields": [{
"name": "test",
"type": {
@@ -1160,6 +1188,7 @@ def test_regular_vs_ordered_dict_map_typeerror():
"""
schema = {
"type": "record",
+ "name": "test_regular_vs_ordered_dict_map_typeerror",
"fields": [{
"name": "test",
"type": {

MODIFY
tests/test_schemaless.py
tests/test_schemaless.py
@@ -28,6 +28,7 @@ def test_schemaless_writer_and_reader():
def test_boolean_roundtrip():
schema = {
"type": "record",
+ "name": "test_boolean_roundtrip",
"fields": [{
"name": "field",
"type": "boolean"

ensure records have a name field