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

Cannot generate Avro schema when using Generic Classes #826

Open
maver1ck opened this issue Jan 21, 2025 · 0 comments
Open

Cannot generate Avro schema when using Generic Classes #826

maver1ck opened this issue Jan 21, 2025 · 0 comments

Comments

@maver1ck
Copy link

Describe the bug
I'm trying to generate Avro Schema for model with Generic Class.

As a result I'm getting following error:

ValueError: Type ~T for field additonal_info is unknown. Please check the valid types at https://marcosschroh.github.io/dataclasses-avroschema/fields_specification/#avro-field-and-python-types-summary

To Reproduce

from typing import TypeVar, Generic
from dataclasses_avroschema import AvroModel
import pydantic


T = TypeVar('T')

@pydantic.dataclasses.dataclass
class UserInfoGeneric(Generic[T], AvroModel):
    name: str
    age: int
    additonal_info: T

@pydantic.dataclasses.dataclass
class EmailInfoGeneric(AvroModel):
    email: str
    is_verified: bool

@pydantic.dataclasses.dataclass
class UserEmailInfo(UserInfoGeneric[EmailInfoGeneric], AvroModel):
    pass

print(UserEmailInfo.fake())

print(UserEmailInfo.avro_schema())

Expected behavior

I'd like to see behaviour similar to example where I'm not using Generic classes.

from typing import TypeVar, Generic
from dataclasses_avroschema import AvroModel
import pydantic

@pydantic.dataclasses.dataclass
class EmailInfo(AvroModel):
    email: str
    is_verified: bool

@pydantic.dataclasses.dataclass
class AddressInfo(AvroModel):
    street: str
    city: str
    state: str
    zip: int

@pydantic.dataclasses.dataclass
class UserInfo(AvroModel):
    name: str
    age: int
    additonal_info: AddressInfo | EmailInfo

print(UserInfo.fake())

print(UserInfo.avro_schema())
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