Closed tebartsch closed 2 years ago
I get a similar but slightly different problem when using the classes
import typing
from dataclasses import dataclass
from dataclasses_avroschema import AvroModel
@dataclass
class S1(AvroModel):
pass
@dataclass
class S2(AvroModel):
pass
@dataclass
class A(AvroModel):
s: typing.Union[S1, S2]
@dataclass
class B(AvroModel):
# class Meta:
# namespace = "namespace_B" # Workaround
a: A
@dataclass
class C(AvroModel):
# class Meta:
# namespace = "namespace_C" # Workaround
b: B
a: A
if __name__ == "__main__":
b = B(a=A(s=S1()))
c = C(b=B(a=A(s=S1())), a=A(s=S1()))
b.serialize()
c.serialize()
In this case the workaround from above using alias_nested_items
does not work. I was only able to fix this by using different namespaces for B
and C
as in this code.
Hi,
Thanks reporting the bug. I will try to fix it asap.
Describe the bug The avro serialization with
fastavro
for three classesA
,B
(depending onA
),C
(depending onA
andB
),fails with
even when using a namespace for
A
.To Reproduce (EDITED: changed from using
dataclasses_avroschema.avrodantic.AvroBaseModel
todataclasses_avroschema.AvroModel
.)Expected behavior The code above should run but fails with the error (i used
dataclasses-avroschema==0.30.3
).