feat: additional recipe sort behavior (#1858)

* changed default sort direction for certain attrs

* added workaround for filtering out null datetimes

* filtered out null-valued results for certain sorts

* removed unecessary parse

* used minyear instead of 1900
This commit is contained in:
Michael Genson
2022-11-30 23:59:30 -06:00
committed by GitHub
parent 33dffccaa5
commit 1b9ff454fb
4 changed files with 39 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
from __future__ import annotations
import datetime
import re
from enum import Enum
from typing import Any, TypeVar, cast
@@ -96,13 +97,20 @@ class QueryFilter:
value: Any = component.value
if isinstance(attr.type, (sqltypes.Date, sqltypes.DateTime)):
try:
value = date_parser.parse(component.value)
# TODO: add support for IS NULL and IS NOT NULL
# in the meantime, this will work for the specific usecase of non-null dates/datetimes
if value in ["none", "null"] and component.relational_operator == RelationalOperator.NOTEQ:
component.relational_operator = RelationalOperator.GTE
value = datetime.datetime(datetime.MINYEAR, 1, 1)
except ParserError as e:
raise ValueError(
f"invalid query string: unknown date or datetime format '{component.value}'"
) from e
else:
try:
value = date_parser.parse(component.value)
except ParserError as e:
raise ValueError(
f"invalid query string: unknown date or datetime format '{component.value}'"
) from e
if isinstance(attr.type, sqltypes.Boolean):
try: