# HG changeset patch # User RhodeCode Admin # Date 2021-07-19 09:53:32 # Node ID 09a1d94486ef93510d28450117feea0cc23b892d # Parent 30f9de28b3de648ddcb6a0359570feda5336761d pull-requests: fix potential crash on providing a wrong order-by type column. diff --git a/rhodecode/model/pull_request.py b/rhodecode/model/pull_request.py --- a/rhodecode/model/pull_request.py +++ b/rhodecode/model/pull_request.py @@ -345,14 +345,14 @@ class PullRequestModel(BaseModel): if only_created: q = q.filter(PullRequest.pull_request_state == PullRequest.STATE_CREATED) - if order_by: - order_map = { - 'name_raw': PullRequest.pull_request_id, - 'id': PullRequest.pull_request_id, - 'title': PullRequest.title, - 'updated_on_raw': PullRequest.updated_on, - 'target_repo': PullRequest.target_repo_id - } + order_map = { + 'name_raw': PullRequest.pull_request_id, + 'id': PullRequest.pull_request_id, + 'title': PullRequest.title, + 'updated_on_raw': PullRequest.updated_on, + 'target_repo': PullRequest.target_repo_id + } + if order_by and order_by in order_map: if order_dir == 'asc': q = q.order_by(order_map[order_by].asc()) else: @@ -499,13 +499,13 @@ class PullRequestModel(BaseModel): pull_request_alias.description.ilike(like_expression), )) - if order_by: - order_map = { - 'name_raw': pull_request_alias.pull_request_id, - 'title': pull_request_alias.title, - 'updated_on_raw': pull_request_alias.updated_on, - 'target_repo': pull_request_alias.target_repo_id - } + order_map = { + 'name_raw': pull_request_alias.pull_request_id, + 'title': pull_request_alias.title, + 'updated_on_raw': pull_request_alias.updated_on, + 'target_repo': pull_request_alias.target_repo_id + } + if order_by and order_by in order_map: if order_dir == 'asc': q = q.order_by(order_map[order_by].asc()) else: @@ -585,13 +585,14 @@ class PullRequestModel(BaseModel): PullRequest.title.ilike(like_expression), PullRequest.description.ilike(like_expression), )) - if order_by: - order_map = { - 'name_raw': PullRequest.pull_request_id, - 'title': PullRequest.title, - 'updated_on_raw': PullRequest.updated_on, - 'target_repo': PullRequest.target_repo_id - } + + order_map = { + 'name_raw': PullRequest.pull_request_id, + 'title': PullRequest.title, + 'updated_on_raw': PullRequest.updated_on, + 'target_repo': PullRequest.target_repo_id + } + if order_by and order_by in order_map: if order_dir == 'asc': q = q.order_by(order_map[order_by].asc()) else: @@ -665,13 +666,13 @@ class PullRequestModel(BaseModel): pull_request_alias.description.ilike(like_expression), )) - if order_by: - order_map = { - 'name_raw': pull_request_alias.pull_request_id, - 'title': pull_request_alias.title, - 'updated_on_raw': pull_request_alias.updated_on, - 'target_repo': pull_request_alias.target_repo_id - } + order_map = { + 'name_raw': pull_request_alias.pull_request_id, + 'title': pull_request_alias.title, + 'updated_on_raw': pull_request_alias.updated_on, + 'target_repo': pull_request_alias.target_repo_id + } + if order_by and order_by in order_map: if order_dir == 'asc': q = q.order_by(order_map[order_by].asc()) else: