From 3818b6d8cfd17b3c03e7816c7fb14e2be3a8166c Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 1 Jul 2024 15:48:49 +0100 Subject: [PATCH 1/3] Using the relationship name rather than the table name - the relationship may have a different name to the related table, this makes it a bit more sensible. --- packages/frontend-core/src/utils/searchFields.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/frontend-core/src/utils/searchFields.js b/packages/frontend-core/src/utils/searchFields.js index dec6e93480..294f2c0f38 100644 --- a/packages/frontend-core/src/utils/searchFields.js +++ b/packages/frontend-core/src/utils/searchFields.js @@ -2,7 +2,6 @@ import { BannedSearchTypes } from "../constants" export function getTableFields(tables, linkField) { const table = tables.find(table => table._id === linkField.tableId) - // TODO: mdrury - add support for this with SQS at some point if (!table || !table.sql) { return [] } @@ -11,7 +10,7 @@ export function getTableFields(tables, linkField) { }) return linkFields.map(field => ({ ...field, - name: `${table.name}.${field.name}`, + name: `${linkField.name}.${field.name}`, })) } From c4ffd37caa18753977a15ebe621914a5e3856a61 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 1 Jul 2024 16:37:38 +0100 Subject: [PATCH 2/3] Adding fix for backwards compat, removing columns (but still filtering on) returns no rows, rather than an error. --- .../src/api/routes/tests/search.spec.ts | 30 ++++++++++++++++--- .../server/src/sdk/app/rows/search/sqs.ts | 12 ++++++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/packages/server/src/api/routes/tests/search.spec.ts b/packages/server/src/api/routes/tests/search.spec.ts index 2d01ec0f6d..5cd28f4506 100644 --- a/packages/server/src/api/routes/tests/search.spec.ts +++ b/packages/server/src/api/routes/tests/search.spec.ts @@ -9,20 +9,20 @@ import { db as dbCore, utils } from "@budibase/backend-core" import * as setup from "./utilities" import { AutoFieldSubType, + BBReferenceFieldSubType, Datasource, EmptyFilterOption, - BBReferenceFieldSubType, FieldType, + RelationshipType, + Row, RowSearchParams, SearchFilters, + SearchResponse, SortOrder, SortType, Table, TableSchema, User, - Row, - RelationshipType, - SearchResponse, } from "@budibase/types" import _ from "lodash" import tk from "timekeeper" @@ -2084,6 +2084,28 @@ describe.each([ }) }) + isInternal && + describe("no column error backwards compat", () => { + beforeAll(async () => { + table = await createTable({ + name: { + name: "name", + type: FieldType.STRING, + }, + }) + }) + + it("shouldn't error when column doesn't exist", async () => { + await expectSearch({ + query: { + string: { + "1:something": "a", + }, + }, + }).toMatch({ rows: [] }) + }) + }) + // lucene can't count the total rows !isLucene && describe("row counting", () => { diff --git a/packages/server/src/sdk/app/rows/search/sqs.ts b/packages/server/src/sdk/app/rows/search/sqs.ts index 0720600a15..e23f3a35b5 100644 --- a/packages/server/src/sdk/app/rows/search/sqs.ts +++ b/packages/server/src/sdk/app/rows/search/sqs.ts @@ -39,7 +39,10 @@ import { import { dataFilters } from "@budibase/shared-core" const builder = new sql.Sql(SqlClient.SQL_LITE) -const NO_SUCH_COLUMN_REGEX = new RegExp(`no such colum.+${USER_COLUMN_PREFIX}`) +const MISSING_COLUMN_REGEX = new RegExp(`no such column: .+`) +const USER_COLUMN_PREFIX_REGEX = new RegExp( + `no such column: .+${USER_COLUMN_PREFIX}` +) function buildInternalFieldList( table: Table, @@ -331,12 +334,17 @@ export async function search( } catch (err: any) { const msg = typeof err === "string" ? err : err.message const syncAndRepeat = - (err.status === 400 && msg?.match(NO_SUCH_COLUMN_REGEX)) || + (err.status === 400 && msg?.match(USER_COLUMN_PREFIX_REGEX)) || (err.status === 404 && msg?.includes(SQLITE_DESIGN_DOC_ID)) if (syncAndRepeat) { await sdk.tables.sqs.syncDefinition() return search(options, table) } + // previously the internal table didn't error when + console.log(JSON.stringify(err)) + if (err.status === 400 && msg?.match(MISSING_COLUMN_REGEX)) { + return { rows: [] } + } throw new Error(`Unable to search by SQL - ${msg}`, { cause: err }) } } From 5ac9fe43fc655f8b52086096e171cc854616b029 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 1 Jul 2024 17:50:34 +0100 Subject: [PATCH 3/3] PR comments. --- packages/server/src/sdk/app/rows/search/sqs.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/server/src/sdk/app/rows/search/sqs.ts b/packages/server/src/sdk/app/rows/search/sqs.ts index e23f3a35b5..e3aedf9de8 100644 --- a/packages/server/src/sdk/app/rows/search/sqs.ts +++ b/packages/server/src/sdk/app/rows/search/sqs.ts @@ -340,8 +340,7 @@ export async function search( await sdk.tables.sqs.syncDefinition() return search(options, table) } - // previously the internal table didn't error when - console.log(JSON.stringify(err)) + // previously the internal table didn't error when a column didn't exist in search if (err.status === 400 && msg?.match(MISSING_COLUMN_REGEX)) { return { rows: [] } }