Skip to content

Commit

Permalink
Raise 400 if a column to be sorted does not exist (#45)
Browse files Browse the repository at this point in the history
fix(api): Raise 400 if a column to be sorted does not exist
  • Loading branch information
TheoLechemia authored Oct 14, 2024
1 parent e11d81a commit 150fe67
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils_flask_sqla/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sqlalchemy import MetaData
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.types import Boolean, Date, DateTime, Integer, Numeric
from werkzeug.exceptions import BadRequest

from .errors import UtilsSqlaError

Expand Down Expand Up @@ -236,7 +237,9 @@ def build_query_order(self, query, parameters):
ordel_col = getattr(self.view.tableDef.columns, col)
if (sort[0:1] or ["ASC"])[0].lower() == "desc":
ordel_col = ordel_col.desc()
return query.order_by(ordel_col)
return query.order_by(ordel_col)
else:
raise BadRequest(f"No column name {col} to sort with")
return query

def set_limit(self, q):
Expand Down

0 comments on commit 150fe67

Please sign in to comment.