records should match via their unqualified names
MODIFY
fastavro/_read.pyx
fastavro/_read.pyx
@@ -103,7 +103,10 @@ cpdef match_schemas(w_schema, r_schema):
raise SchemaResolutionError(
f"Schema mismatch: {w_schema} size is different than {r_schema} size"
)
- if w_schema["name"] == r_schema["name"] or w_schema["name"] in r_schema.get(
+
+ w_unqual_name = w_schema["name"].split(".")[-1]
+ r_unqual_name = r_schema["name"].split(".")[-1]
+ if w_unqual_name == r_unqual_name or w_schema["name"] in r_schema.get(
"aliases", []
):
return r_schema

MODIFY
fastavro/_read_py.py
fastavro/_read_py.py
@@ -102,7 +102,10 @@ def match_schemas(w_schema, r_schema):
raise SchemaResolutionError(
f"Schema mismatch: {w_schema} size is different than {r_schema} size"
)
- if w_schema["name"] == r_schema["name"] or w_schema["name"] in r_schema.get(
+
+ w_unqual_name = w_schema["name"].split(".")[-1]
+ r_unqual_name = r_schema["name"].split(".")[-1]
+ if w_unqual_name == r_unqual_name or w_schema["name"] in r_schema.get(
"aliases", []
):
return r_schema

MODIFY
tests/test_schema_evolution.py
tests/test_schema_evolution.py
@@ -751,3 +751,28 @@ def test_union_of_schemas_evolution():
output_using_new_schema = bytes_with_schema_to_avro(new_schema, binary)
assert output_using_new_schema == {"three": {"other_two": 1.0, "new_three": 0.0}}
+
+
+def test_records_match_by_unnamespaced_name():
+ """https://issues.apache.org/jira/browse/AVRO-3561"""
+ original_schema = {
+ "name": "ns.test_record",
+ "type": "record",
+ "fields": [{"name": "f1", "type": "int"}],
+ }
+
+ new_schema = {
+ "name": "ns.foo.test_record",
+ "type": "record",
+ "fields": [
+ {"name": "f1", "type": "int"},
+ {"name": "f2", "type": "int", "default": 3},
+ ],
+ }
+
+ record = {"f1": 0}
+
+ binary = avro_to_bytes_with_schema(original_schema, record)
+
+ output_using_new_schema = bytes_with_schema_to_avro(new_schema, binary)
+ assert output_using_new_schema == {"f1": 0, "f2": 3}

records should match via their unqualified names