1
0
Fork 0
mirror of synced 2024-09-29 16:51:33 +13:00

Fixing an issue with automations being unable to access app databases due to new context stack up.

This commit is contained in:
mike12345567 2022-07-18 17:38:58 +01:00
parent 16b81bfc95
commit 0a7ceda807
2 changed files with 6 additions and 11 deletions

View file

@ -67,6 +67,7 @@ export const getTenantIDFromAppID = (appId: string) => {
// used for automations, API endpoints should always be in context already // used for automations, API endpoints should always be in context already
export const doInTenant = (tenantId: string | null, task: any) => { export const doInTenant = (tenantId: string | null, task: any) => {
tenantId = tenantId || DEFAULT_TENANT_ID
// the internal function is so that we can re-use an existing // the internal function is so that we can re-use an existing
// context - don't want to close DB on a parent context // context - don't want to close DB on a parent context
async function internal(opts = { existing: false }) { async function internal(opts = { existing: false }) {

View file

@ -3,9 +3,7 @@ const actions = require("../automations/actions")
const automationUtils = require("../automations/automationUtils") const automationUtils = require("../automations/automationUtils")
const AutomationEmitter = require("../events/AutomationEmitter") const AutomationEmitter = require("../events/AutomationEmitter")
const { processObject } = require("@budibase/string-templates") const { processObject } = require("@budibase/string-templates")
const { DEFAULT_TENANT_ID } = require("@budibase/backend-core/constants")
const { DocumentTypes } = require("../db/utils") const { DocumentTypes } = require("../db/utils")
const { doInTenant } = require("@budibase/backend-core/tenancy")
const { definitions: triggerDefs } = require("../automations/triggerInfo") const { definitions: triggerDefs } = require("../automations/triggerInfo")
const { doInAppContext, getAppDB } = require("@budibase/backend-core/context") const { doInAppContext, getAppDB } = require("@budibase/backend-core/context")
const { AutomationErrors, LoopStepTypes } = require("../constants") const { AutomationErrors, LoopStepTypes } = require("../constants")
@ -134,7 +132,6 @@ class Orchestrator {
async execute() { async execute() {
let automation = this._automation let automation = this._automation
const app = await this.getApp()
let stopped = false let stopped = false
let loopStep = null let loopStep = null
@ -264,14 +261,11 @@ class Orchestrator {
inputs = automationUtils.cleanInputValues(inputs, step.schema.inputs) inputs = automationUtils.cleanInputValues(inputs, step.schema.inputs)
try { try {
// appId is always passed // appId is always passed
let tenantId = app.tenantId || DEFAULT_TENANT_ID const outputs = await stepFn({
const outputs = await doInTenant(tenantId, () => { inputs: inputs,
return stepFn({ appId: this._appId,
inputs: inputs, emitter: this._emitter,
appId: this._appId, context: this._context,
emitter: this._emitter,
context: this._context,
})
}) })
this._context.steps[stepCount] = outputs this._context.steps[stepCount] = outputs
// if filter causes us to stop execution don't break the loop, set a var // if filter causes us to stop execution don't break the loop, set a var