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

take pydantic's alias into account when serializing AvroBaseModel #802

Open
RuiLoureiro opened this issue Nov 28, 2024 · 0 comments
Open

Comments

@RuiLoureiro
Copy link

RuiLoureiro commented Nov 28, 2024

Describe the bug

I have an AvroBaseModel with a field named schema.
Because schema is already a method defined in pydantic's BaseModel I have to use an alias.

I am trying to serialize this model using https://github.com/marcosschroh/python-schema-registry-client.

The issue is that AvroBaseModel.asdict() ignores the alias

To Reproduce

from dataclasses_avroschema.pydantic import AvroBaseModel
from pydantic import Field

class Foo(AvroBaseModel):
    schema_: str = Field(alias='schema')

foo = Foo(schema='bar')

# raises error
assert 'schema' in foo.asdict()

Expected behavior

I would expect that when an AvroBaseModel is serialized, it would use the alias of each field (in this case, schema instead of schema_)

@RuiLoureiro RuiLoureiro changed the title AvroBaseModel.asdict() does not respect pydantic's serialization_alias take pydantic's alias into account when serializing AvroBaseModel Nov 28, 2024
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

1 participant