Circular dependency errors 2

I'm getting circular dependency errors and not sure why.

Is it because I'm triggering these queries inside of a JavaScript query?

Even so, I'm not triggering them in a circular way.

1 Like

Is it possible for you to post some screenshots?

Sure, here's a code sample from one of my JavaScript queries. It's the only place that references queries CR_insert and CRI_insert.

const selectedRows = tableCreate.selectedRow.data
console.log('selectedRows ', selectedRows)

const totalAmount = selectedRows.reduce((acc, row) => acc + Number(row.paymentAmount), 0)
console.log('totalAmount ', totalAmount)

const cashflowReportCuid = cuid()
console.log('cashflowReportCuid ', cashflowReportCuid)

const cashflowReport = {
  cuid: cashflowReportCuid,
  modified_at: new Date(),
  status: 'PENDING',
  total_amount: totalAmount,
  approved_on_date: new Date()
}

const createCashflowReport = () => {
  return new Promise((resolve, reject) => {
    CR_insert.trigger({
      additionalScope: {
        changeset: cashflowReport
      },
      onSuccess: (data) => {
        console.log('data ', data)
        resolve(data)
      },
      onFailure: (error) => {
        console.error('error ', error)
        reject(error)
      }
    })
  })
} 

const cashflowReportItems = selectedRows.map((item) => ({
  cuid: cuid(),
  modified_at: new Date(),
  tenant_account_cuid: item.tenantAccountCuid,
  cashflow_report_cuid: cashflowReportCuid,
  status: 'STAGED',
  queued_amount: item.paymentAmount,
  scheduled_payment_date: item.paymentDate
}))
console.log('cashflowReportItems ', cashflowReportItems)

const createCashflowReportItems = () => {
  return new Promise((resolve, reject) => {
    CRI_insert.trigger({
      additionalScope: {
        changeset: cashflowReportItems
      },
      onSuccess: (data) => {
        console.log('data ', data)
        resolve(data)
      },
      onFailure: (error) => {
        console.error('error ', error)
        reject(error)
      }
    })
  })
}

await createCashflowReport()
  .then(async () => {
    await createCashflowReportItems()
      .then(() => {
        utils.showNotification({
          title: "Payments staged",
          notificationType: "success"
        })
        modalCreateStage.close()
        selectStaged.trigger()
        tableCreate.selectRow()
      })
      .catch((e) => {
        utils.showNotification({
          title: "Error staging payments",
          notificationType: "error"
        })
        throw Error(e)
      })
  })
  .catch((e) => {
    utils.showNotification({
      title: "Error staging payments",
      notificationType: "error"
    })
    throw Error(e)
  })

Hey @johnwp!

If there's a dependency cycle usually indicates that the component itself is self-referential, so clues would likely be found in the settings for the query. Would you mind sending over screenshots of those?

Hi @Kabirdas, thanks so much for the reply!

Sure, here are some screenshots of one of the queries (CRI_Update) reported to have a circular dependency.

Hey folks!

Just want to post here for anyone who might be running into a similar issue! The dependency cycle error was caused by how self was being referenced elsewhere in the query, particularly SQL mode and "Bulk update via primary key", even though they weren't currently active. If you're seeing bugs come up and there doesn't seem to be a clear place they're coming from it can be helpful to check unused settings as well, since those are still saved!

2 Likes