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

Nested Enums Raise Error #208

Closed
LaurenzReitsam opened this issue Oct 14, 2022 · 0 comments
Closed

Nested Enums Raise Error #208

LaurenzReitsam opened this issue Oct 14, 2022 · 0 comments

Comments

@LaurenzReitsam
Copy link

LaurenzReitsam commented Oct 14, 2022

Describe the bug
There seems to be a bug in AvroModel.serialize() with Enums if they are used in the following structure:

class AvroModel1:
    foo: Enum

class AvroModel2:
    bar: list[AvroModel1]

To Reproduce

pip install dataclasses-avroschema==0.32.1

import enum
from dataclasses_avroschema import AvroModel
from dataclasses import dataclass

class FavoriteColor(enum.Enum):
    BLUE = "BLUE"
    YELLOW = "YELLOW"
    GREEN = "GREEN"

@dataclass
class UserModel(AvroModel):
    color: FavoriteColor = FavoriteColor.BLUE

@dataclass
class GroupModel(AvroModel):
    users: list[UserModel]

user = UserModel()
group = GroupModel([user])
group.serialize()

raises
ValueError: <FavoriteColor.BLUE: 'BLUE'> is not in list

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