Skip to content

Commit

Permalink
Guard against invalid sorting fields in report generation (#458)
Browse files Browse the repository at this point in the history
Signed-off-by: Simeon Widdis <[email protected]>
(cherry picked from commit 7f69dc4)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Nov 4, 2024
1 parent 3db1c45 commit 0eeac89
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions server/routes/utils/dataReportHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,21 @@ export const buildRequestBody = (
.query(esbBoolQuery)
.version(true);

if (report._source.sorting.length > 0) {
const sortings: Sort[] = report._source.sorting.map((element: string[]) => {
let sorting: string[][] = report._source.sorting;

// We expect a list of [field, order] pairs for sorting. In some migration paths, though it's not
// clear why, this list can get unnested in the case of one sort, [["field", "asc"]] becomes
// ["field", "asc"]. The true root cause remains a mystery, so we work around it.
// See: https://github.com/opensearch-project/dashboards-reporting/issues/371
if (sorting.length > 0 && typeof sorting[0] === "string") {
sorting = [(sorting as unknown as string[])];
}

if (sorting.length > 0) {
const sorts: Sort[] = sorting.map((element: string[]) => {
return esb.sort(element[0], element[1]);
});
esbSearchQuery.sorts(sortings);
esbSearchQuery.sorts(sorts);
}

// add selected fields to query
Expand Down

0 comments on commit 0eeac89

Please sign in to comment.