Skip to content
Merged
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
9 changes: 7 additions & 2 deletions services/query_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from fastapi import HTTPException
from fastapi_pagination.ext.sqlalchemy import paginate
from sqlalchemy import select, Float, Integer, Column, Select, func
from sqlalchemy import select, Float, Integer, Column, Select, func, String
from sqlalchemy.orm import DeclarativeBase, Session
from sqlalchemy.sql.elements import OperatorExpression
from starlette.status import HTTP_404_NOT_FOUND
Expand Down Expand Up @@ -130,7 +130,12 @@ def order_sort_filter(
"Sort parameter is required when order is specified. "
f"The sort parameter should be a column name in the table {table}."
)
attr = func.lower(getattr(table, sort))

attr = getattr(table, sort)
# test if column is a string col
if isinstance(attr.type, String):
attr = func.lower(attr)

if order.lower() == "asc":
sql = sql.order_by(attr.asc())
elif order.lower() == "desc":
Expand Down
Loading