Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/persons/test_person_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def setUp(self):
{"duration": 300},
)

def test_get_persons_filtered_by_choice_field(self):
# Filtering on a ChoiceType column (role) used to 500: its SQLAlchemy
# type raises NotImplementedError for python_type.
persons = self.get("data/persons?role=admin")
self.assertTrue(len(persons) >= 1)
self.assertTrue(all(p["role"] == "admin" for p in persons))

# --- Time spents ---

def test_get_person_time_spents(self):
Expand Down
11 changes: 9 additions & 2 deletions zou/app/utils/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,19 @@ def apply_sort_by(model, query, sort_by):


def cast_value(value, field_key):
if field_key.type.python_type is bool:
# Some column types (ChoiceType, LocaleType, TimezoneType, ...) do not
# implement python_type and raise NotImplementedError; they just fall
# through to the generic cast below instead of crashing the request.
try:
python_type = field_key.type.python_type
except NotImplementedError:
python_type = None
if python_type is bool:
try:
return string.strtobool(value)
except ValueError:
raise WrongParameterException(f"Invalid boolean value: {value}")
elif field_key.type.python_type is uuid.UUID:
elif python_type is uuid.UUID:
if (
value
and not isinstance(value, uuid.UUID)
Expand Down
Loading