Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise 400 if a column of order does not exit #45

Merged
merged 1 commit into from
Oct 14, 2024
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
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 @@ -234,7 +235,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
Loading