@@ -467,6 +467,86 @@ async def test_avro_serialize_union_with_references():
467467 assert obj == obj2
468468
469469
470+ async def test_avro_diamond_dependency_references ():
471+ # Two sibling references (OrderDetails, InvoiceDetails) both depend on the
472+ # same named type (Address). Without the fix in _resolve_named_schema, each
473+ # branch is pre-parsed with Address inlined, and the top-level parse then
474+ # raises SchemaParseException("redefined named type ...Address").
475+ conf = {'url' : _BASE_URL }
476+ client = AsyncSchemaRegistryClient .new_client (conf )
477+ ser_conf = {'auto.register.schemas' : False , 'use.latest.version' : True }
478+
479+ ns = "com.example.diamond"
480+ address_schema = {
481+ 'type' : 'record' ,
482+ 'name' : 'Address' ,
483+ 'namespace' : ns ,
484+ 'fields' : [{'name' : 'street' , 'type' : 'string' }],
485+ }
486+ order_schema = {
487+ 'type' : 'record' ,
488+ 'name' : 'OrderDetails' ,
489+ 'namespace' : ns ,
490+ 'fields' : [{'name' : 'shipping_address' , 'type' : f'{ ns } .Address' }],
491+ }
492+ invoice_schema = {
493+ 'type' : 'record' ,
494+ 'name' : 'InvoiceDetails' ,
495+ 'namespace' : ns ,
496+ 'fields' : [{'name' : 'billing_address' , 'type' : f'{ ns } .Address' }],
497+ }
498+ root_schema = {
499+ 'type' : 'record' ,
500+ 'name' : 'OrderEvent' ,
501+ 'namespace' : ns ,
502+ 'fields' : [
503+ {'name' : 'order' , 'type' : f'{ ns } .OrderDetails' },
504+ {'name' : 'invoice' , 'type' : f'{ ns } .InvoiceDetails' },
505+ ],
506+ }
507+
508+ await client .register_schema ('diamond-Address' , Schema (json .dumps (address_schema )))
509+ await client .register_schema (
510+ 'diamond-OrderDetails' ,
511+ Schema (
512+ json .dumps (order_schema ),
513+ 'AVRO' ,
514+ [SchemaReference (f'{ ns } .Address' , 'diamond-Address' , 1 )],
515+ ),
516+ )
517+ await client .register_schema (
518+ 'diamond-InvoiceDetails' ,
519+ Schema (
520+ json .dumps (invoice_schema ),
521+ 'AVRO' ,
522+ [SchemaReference (f'{ ns } .Address' , 'diamond-Address' , 1 )],
523+ ),
524+ )
525+ await client .register_schema (
526+ _SUBJECT ,
527+ Schema (
528+ json .dumps (root_schema ),
529+ 'AVRO' ,
530+ [
531+ SchemaReference (f'{ ns } .OrderDetails' , 'diamond-OrderDetails' , 1 ),
532+ SchemaReference (f'{ ns } .InvoiceDetails' , 'diamond-InvoiceDetails' , 1 ),
533+ ],
534+ ),
535+ )
536+
537+ obj = {
538+ 'order' : {'shipping_address' : {'street' : '123 Main St' }},
539+ 'invoice' : {'billing_address' : {'street' : '456 Elm St' }},
540+ }
541+ ser = await AsyncAvroSerializer (client , schema_str = None , conf = ser_conf )
542+ ser_ctx = SerializationContext (_TOPIC , MessageField .VALUE )
543+ obj_bytes = await ser (obj , ser_ctx )
544+
545+ deser = await AsyncAvroDeserializer (client )
546+ obj2 = await deser (obj_bytes , ser_ctx )
547+ assert obj == obj2
548+
549+
470550async def test_avro_schema_evolution ():
471551 conf = {'url' : _BASE_URL }
472552 client = AsyncSchemaRegistryClient .new_client (conf )
0 commit comments