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 use StrEnum fields in DataModel #173

Open
piotr-rarus opened this issue Sep 25, 2024 · 1 comment
Open

Cannot use StrEnum fields in DataModel #173

piotr-rarus opened this issue Sep 25, 2024 · 1 comment

Comments

@piotr-rarus
Copy link
Collaborator

Draive is unable to build a validator for StrEnum. It uses list_validator but doesn't get a range of available values.

Error:

draive.parameters.errors.ParameterValidationError: ("Validation error: Invalid parameter value at: %s - expected '%s' while received '%s'", UserProfileDraive.goals[0], (), <Goal.GENERAL_WELLNESS: 'GENERAL_WELLNESS'>)

Example code:

from enum import StrEnum
from draive import DataModel


class Goal(StrEnum):
    GENERAL_WELLNESS = "GENERAL_WELLNESS"
    INCREASE_ENERGY = "INCREASE_ENERGY"
    ENHANCE_FOCUS = "ENHANCE_FOCUS"
    OTHER = "OTHER"

class UserProfileDraive(DataModel):
    name: str
    goals: list[Goal]

user_profile_draive = UserProfileDraive(name='Piotr', goals=[Goal.GENERAL_WELLNESS])
user_profile_draive_json = user_profile_draive.as_json()
print(user_profile_draive_json)
@KaQuMiQ
Copy link
Collaborator

KaQuMiQ commented Oct 9, 2024

It seems that there is some missing part when decoding Enum based types, I will take a closer look at it

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