Skip to content

Commit

Permalink
more robust value type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
dantownsend committed Oct 30, 2019
1 parent 8185fd0 commit c499551
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions piccolo_api/crud/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typing as t

from piccolo.table import Table
from piccolo.columns.column_types import ForeignKey
from piccolo.columns.column_types import ForeignKey, Varchar, Text
import pydantic
from pydantic.error_wrappers import ValidationError
from starlette.exceptions import HTTPException
Expand Down Expand Up @@ -138,11 +138,14 @@ async def _get_all(self, params: t.Optional[t.Dict] = None):
model_dict = self.pydantic_model(**params).dict()
for field_name in params.keys():
value = model_dict[field_name]
if type(value) == str:
if isinstance(
self.table._meta.get_column_by_name(field_name),
(Varchar, Text),
):
query = query.where(
getattr(self.table, field_name).ilike(f"%{value}%")
)
elif type(value) in [int, float]:
else:
query = query.where(
getattr(self.table, field_name) == value
)
Expand Down

0 comments on commit c499551

Please sign in to comment.