Skip to content

Commit

Permalink
Adding fix for backwards compat, removing columns (but still filterin…
Browse files Browse the repository at this point in the history
…g on) returns no rows, rather than an error.
  • Loading branch information
mike12345567 committed Jul 1, 2024
1 parent 3818b6d commit c4ffd37
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
30 changes: 26 additions & 4 deletions packages/server/src/api/routes/tests/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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", () => {
Expand Down
12 changes: 10 additions & 2 deletions packages/server/src/sdk/app/rows/search/sqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 })
}
}

0 comments on commit c4ffd37

Please sign in to comment.