order-by-text-fix
All checks were successful
Deploy on push / deploy (push) Successful in 1m39s

This commit is contained in:
Untone 2024-02-25 17:39:38 +03:00
parent ad1bb4af19
commit 26c12b2aad

View File

@ -1,4 +1,4 @@
from sqlalchemy import bindparam, distinct, or_ from sqlalchemy import bindparam, distinct, or_, text
from sqlalchemy.orm import aliased, joinedload, selectinload from sqlalchemy.orm import aliased, joinedload, selectinload
from sqlalchemy.sql.expression import and_, asc, case, desc, func, nulls_last, select from sqlalchemy.sql.expression import and_, asc, case, desc, func, nulls_last, select
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
@ -143,9 +143,10 @@ async def load_shouts_by(_, _info, options):
q = q.group_by(Shout.id) q = q.group_by(Shout.id)
# order # order
order_by = options.get( order_by = Shout.featured_at if filters.get('featured') else Shout.published_at
'order_by', Shout.featured_at if filters.get('featured') else Shout.published_at order_by_str = options.get('order_by')
) if order_by_str:
order_by = text(order_by_str)
query_order_by = ( query_order_by = (
desc(order_by) if options.get('order_by_desc', True) else asc(order_by) desc(order_by) if options.get('order_by_desc', True) else asc(order_by)
) )