Merge pull request #6609 from Budibase/fix/rest-query-retry-mutation
Fixed expression mutation
This commit is contained in:
commit
8cead5c2b8
|
@ -218,7 +218,6 @@ describe("/queries", () => {
|
||||||
expect(res.body.schemaFields).toEqual(["a", "b"])
|
expect(res.body.schemaFields).toEqual(["a", "b"])
|
||||||
expect(res.body.rows.length).toEqual(1)
|
expect(res.body.rows.length).toEqual(1)
|
||||||
expect(events.query.previewed).toBeCalledTimes(1)
|
expect(events.query.previewed).toBeCalledTimes(1)
|
||||||
datasource.config = { schema: "public" }
|
|
||||||
expect(events.query.previewed).toBeCalledWith(datasource, query)
|
expect(events.query.previewed).toBeCalledWith(datasource, query)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ const {
|
||||||
} = require("@budibase/backend-core/auth")
|
} = require("@budibase/backend-core/auth")
|
||||||
const { user: userCache } = require("@budibase/backend-core/cache")
|
const { user: userCache } = require("@budibase/backend-core/cache")
|
||||||
const { getGlobalIDFromUserMetadataID } = require("../db/utils")
|
const { getGlobalIDFromUserMetadataID } = require("../db/utils")
|
||||||
|
const { cloneDeep } = require("lodash/fp")
|
||||||
|
|
||||||
const { isSQL } = require("../integrations/utils")
|
const { isSQL } = require("../integrations/utils")
|
||||||
const {
|
const {
|
||||||
|
@ -41,20 +42,22 @@ class QueryRunner {
|
||||||
async execute() {
|
async execute() {
|
||||||
let { datasource, fields, queryVerb, transformer } = this
|
let { datasource, fields, queryVerb, transformer } = this
|
||||||
|
|
||||||
const Integration = integrations[datasource.source]
|
let datasourceClone = cloneDeep(datasource)
|
||||||
|
let fieldsClone = cloneDeep(fields)
|
||||||
|
|
||||||
|
const Integration = integrations[datasourceClone.source]
|
||||||
if (!Integration) {
|
if (!Integration) {
|
||||||
throw "Integration type does not exist."
|
throw "Integration type does not exist."
|
||||||
}
|
}
|
||||||
|
|
||||||
if (datasource.config.authConfigs) {
|
if (datasourceClone.config.authConfigs) {
|
||||||
datasource.config.authConfigs = datasource.config.authConfigs.map(
|
datasourceClone.config.authConfigs =
|
||||||
config => {
|
datasourceClone.config.authConfigs.map(config => {
|
||||||
return enrichQueryFields(config, this.ctx)
|
return enrichQueryFields(config, this.ctx)
|
||||||
}
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const integration = new Integration(datasource.config)
|
const integration = new Integration(datasourceClone.config)
|
||||||
|
|
||||||
// pre-query, make sure datasource variables are added to parameters
|
// pre-query, make sure datasource variables are added to parameters
|
||||||
const parameters = await this.addDatasourceVariables()
|
const parameters = await this.addDatasourceVariables()
|
||||||
|
@ -65,19 +68,19 @@ class QueryRunner {
|
||||||
const enrichedContext = { ...enrichedParameters, ...this.ctx }
|
const enrichedContext = { ...enrichedParameters, ...this.ctx }
|
||||||
|
|
||||||
// Parse global headers
|
// Parse global headers
|
||||||
if (datasource.config.defaultHeaders) {
|
if (datasourceClone.config.defaultHeaders) {
|
||||||
datasource.config.defaultHeaders = enrichQueryFields(
|
datasourceClone.config.defaultHeaders = enrichQueryFields(
|
||||||
datasource.config.defaultHeaders,
|
datasourceClone.config.defaultHeaders,
|
||||||
enrichedContext
|
enrichedContext
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let query
|
let query
|
||||||
// handle SQL injections by interpolating the variables
|
// handle SQL injections by interpolating the variables
|
||||||
if (isSQL(datasource)) {
|
if (isSQL(datasourceClone)) {
|
||||||
query = interpolateSQL(fields, enrichedParameters, integration)
|
query = interpolateSQL(fieldsClone, enrichedParameters, integration)
|
||||||
} else {
|
} else {
|
||||||
query = enrichQueryFields(fields, enrichedContext)
|
query = enrichQueryFields(fieldsClone, enrichedContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add pagination values for REST queries
|
// Add pagination values for REST queries
|
||||||
|
@ -116,9 +119,10 @@ class QueryRunner {
|
||||||
await this.refreshOAuth2(this.ctx)
|
await this.refreshOAuth2(this.ctx)
|
||||||
// Attempt to refresh the access token from the provider
|
// Attempt to refresh the access token from the provider
|
||||||
this.hasRefreshedOAuth = true
|
this.hasRefreshedOAuth = true
|
||||||
|
} else {
|
||||||
|
this.hasRerun = true
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hasRerun = true
|
|
||||||
await threadUtils.invalidateDynamicVariables(this.cachedVariables)
|
await threadUtils.invalidateDynamicVariables(this.cachedVariables)
|
||||||
return this.execute()
|
return this.execute()
|
||||||
}
|
}
|
||||||
|
@ -187,8 +191,9 @@ class QueryRunner {
|
||||||
} else {
|
} else {
|
||||||
// In this event the user may have oAuth issues that
|
// In this event the user may have oAuth issues that
|
||||||
// could require re-authenticating with their provider.
|
// could require re-authenticating with their provider.
|
||||||
|
let errorMessage = resp.err.data ? resp.err.data : resp.err.toString()
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"OAuth2 access token could not be refreshed: " + resp.err.toString()
|
"OAuth2 access token could not be refreshed: " + errorMessage
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue