From 16552df4c5862004f63a8d8a7c0f8e0dd16f8a0e Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Wed, 2 Dec 2020 14:14:57 +0200 Subject: Fix form features validation and allow passing ID as id not _id --- backend/models/form.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/models/form.py b/backend/models/form.py index 79d1d54..a8c5f92 100644 --- a/backend/models/form.py +++ b/backend/models/form.py @@ -13,12 +13,16 @@ class Form(BaseModel): features: t.List[str] questions: t.List[Question] + class Config: + allow_population_by_field_name = True + @validator("features") def validate_features(cls, value: t.List[str]) -> t.Optional[t.List[str]]: """Validates is all features in allowed list.""" # Uppercase everything to avoid mixed case in DB value = [v.upper() for v in value] - if not all(v in FormFeatures.__members__.values() for v in value): + allowed_values = list(v.value for v in FormFeatures.__members__.values()) + if not all(v in allowed_values for v in value): raise ValueError("Form features list contains one or more invalid values.") if FormFeatures.COLLECT_EMAIL in value and FormFeatures.REQUIRES_LOGIN not in value: # noqa -- cgit v1.2.3