From 26c12b2aad37ee166e47517f7a31d1843a4923c1 Mon Sep 17 00:00:00 2001 From: Untone Date: Sun, 25 Feb 2024 17:39:38 +0300 Subject: [PATCH] order-by-text-fix --- resolvers/reader.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/resolvers/reader.py b/resolvers/reader.py index ff4b558a..deb549c2 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -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.sql.expression import and_, asc, case, desc, func, nulls_last, select from starlette.exceptions import HTTPException @@ -143,9 +143,10 @@ async def load_shouts_by(_, _info, options): q = q.group_by(Shout.id) # 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 = ( desc(order_by) if options.get('order_by_desc', True) else asc(order_by) )