Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typing.List[AvroModel] works but typing.Dict[str, AvroModel] seems to fail #184

Closed
mattreid9956 opened this issue Jul 18, 2022 · 1 comment

Comments

@mattreid9956
Copy link

mattreid9956 commented Jul 18, 2022

Describe the bug
Should dictionary representations be deserializable when using "avro-json" I find a case where "avro" works but "avro-json" does not (ps. cool repo!).

To Reproduce
Take your original Address+User examples and changing typing.List -> typing.Dict[str,Address]

import typing
import dataclasses
from dataclasses_avroschema import AvroModel

@dataclasses.dataclass
class Address(AvroModel):
    "An Address"
    street: str
    street_number: int

@dataclasses.dataclass
class User(AvroModel):
    "User with multiple Address"
    name: str
    age: int
    addresses: typing.Dict[str, Address]

user = User.fake()

# Fails with error "ValueError: no value and no default" raised from generator fastavro.json_reader(input_stream, schema)
serialization_type = 'avro-json'
s = user.serialize(serialization_type=serialization_type)
User.deserialize(s, serialization_type=serialization_type)

Expected behavior
The same output as with the "avro" serialization type (as below) - just wanted to report this and confirm that this is the expected behaviour?

# Works fine
serialization_type = 'avro'
s = user.serialize(serialization_type=serialization_type)
User.deserialize(s, serialization_type=serialization_type)

python: 3.7.8
dataclasses-avroschema==0.30.0
fastavro==1.5.2

@mattreid9956 mattreid9956 changed the title typing.List[AvroModel] works but typing.Dict[str, AvroModel] typing.List[AvroModel] works but typing.Dict[str, AvroModel] seems to fail Jul 18, 2022
@marcosschroh
Copy link
Owner

Hi @mattreid9956

Thanks for reporting the issue. It looks like it's a bug in fastavro. I have reported the issue: fastavro/fastavro#629

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants