-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from Flagsmith/fix/trait-value-str-coercion
fix: restore trait value coercion to string
- Loading branch information
Showing
2 changed files
with
15 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
from pydantic import BaseModel | ||
from typing import Any, get_args | ||
|
||
from pydantic import BaseModel, validator | ||
|
||
from flag_engine.identities.traits.types import TraitValue | ||
|
||
TRAIT_VALUE_TYPES = get_args(TraitValue) | ||
|
||
|
||
class TraitModel(BaseModel): | ||
trait_key: str | ||
trait_value: TraitValue = ... | ||
|
||
@validator("trait_value", pre=True) | ||
def convert_trait_value(cls, value: Any) -> TraitValue: | ||
if isinstance(value, TRAIT_VALUE_TYPES): | ||
return value | ||
return str(value) | ||
|
||
class Config: | ||
smart_union: bool = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters