Making sure table IDs input are correctly formatted for comparison.

This commit is contained in:
mike12345567 2024-12-12 14:02:52 +00:00
parent 1c5a973ec0
commit 635049ab0f
4 changed files with 26 additions and 14 deletions

View File

@ -4,8 +4,8 @@ import {
getContainerRuntimeClient,
} from "testcontainers"
import { ContainerInfo } from "dockerode"
import path from "path"
import lockfile from "proper-lockfile"
import * as path from "path"
import * as lockfile from "proper-lockfile"
import { execSync } from "child_process"
interface DockerContext {
@ -29,8 +29,8 @@ function getCurrentDockerContext(): DockerContext {
async function getBudibaseContainers() {
const client = await getContainerRuntimeClient()
const conatiners = await client.container.list()
return conatiners.filter(
const containers = await client.container.list()
return containers.filter(
container =>
container.Labels["com.budibase"] === "true" &&
container.Labels["org.testcontainers"] === "true"

View File

@ -66,6 +66,14 @@ export function buildExternalTableId(datasourceId: string, tableName: string) {
return `${datasourceId}${DOUBLE_SEPARATOR}${tableName}`
}
export function checkTableId(tableId: string) {
if (isExternalTableID(tableId) && tableId.includes(" ")) {
return encodeURIComponent(tableId)
} else {
return tableId
}
}
export function breakExternalTableId(tableId: string) {
const parts = tableId.split(DOUBLE_SEPARATOR)
let datasourceId = parts.shift()

View File

@ -288,19 +288,21 @@ function replaceTableNamesInFilters(
for (const key of Object.keys(filter)) {
const matches = key.match(`^(?<relation>.+)\\.(?<field>.+)`)
const relation = matches?.groups?.["relation"]
// this is the possible table name which we need to check if it needs to be converted
const relatedTableName = matches?.groups?.["relation"]
const field = matches?.groups?.["field"]
if (!relation || !field) {
if (!relatedTableName || !field) {
continue
}
const table = allTables.find(r => r._id === tableId)!
if (Object.values(table.schema).some(f => f.name === relation)) {
const table = allTables.find(r => r._id === tableId)
const isColumnName = !!table?.schema[relatedTableName]
if (!table || isColumnName) {
continue
}
const matchedTable = allTables.find(t => t.name === relation)
const matchedTable = allTables.find(t => t.name === relatedTableName)
const relationship = Object.values(table.schema).find(
f => isRelationshipField(f) && f.tableId === matchedTable?._id
)

View File

@ -1,6 +1,6 @@
import * as utils from "../../../../db/utils"
import { docIds } from "@budibase/backend-core"
import { docIds, sql } from "@budibase/backend-core"
import {
Ctx,
DatasourcePlusQueryResponse,
@ -65,19 +65,21 @@ export function getSourceId(ctx: Ctx): { tableId: string; viewId?: string } {
const { sourceId } = ctx.params
if (docIds.isViewId(sourceId)) {
return {
tableId: utils.extractViewInfoFromID(sourceId).tableId,
tableId: sql.utils.checkTableId(
utils.extractViewInfoFromID(sourceId).tableId
),
viewId: sourceId,
}
}
return { tableId: ctx.params.sourceId }
return { tableId: sql.utils.checkTableId(ctx.params.sourceId) }
}
// now check for old way of specifying table ID
if (ctx.params?.tableId) {
return { tableId: ctx.params.tableId }
return { tableId: sql.utils.checkTableId(ctx.params.tableId) }
}
// check body for a table ID
if (ctx.request.body?.tableId) {
return { tableId: ctx.request.body.tableId }
return { tableId: sql.utils.checkTableId(ctx.request.body.tableId) }
}
throw new Error("Unable to find table ID in request")
}