Error with Nested Transactions

I'm experiencing an issue with nested transactions on neon serverless 0.9.1, drizzle-orm 0.30.9, and ws 8.16.0.

The following works locally but not in production:
async function createOrGet<T>(
    parentTxn: DbTransaction<T>,
    entity: NewEntity,
): Promise<string | null> {
    try {
        return await parentTxn.transaction(async (childTxn) => {
            return await createInTxn(childTxn, entity)
        })
    } catch (e: unknown) {
        if (isDbErrorWithCode(e, PostgresErrorCode.UNIQUE_VIOLATION)) {
            return await findWorkflowTemplateByNameInTxn(parentTxn, entity.id)
        } else {
            return null
        }
    }
}


The following works in production but not locally:
async function createOrGet<T>(
    parentTxn: DbTransaction<T>,
    entity: NewEntity,
): Promise<string | null> {
    try {
      return await createInTxn(parentTxn, entity)
    } catch (e: unknown) {
        if (isDbErrorWithCode(e, PostgresErrorCode.UNIQUE_VIOLATION)) {
            return await findWorkflowTemplateByNameInTxn(parentTxn, entity.id)
        } else {
            return null
        }
    }
}


I'd expect the 1st (parent-child transactions) to work. Instead, I get a 25P01 error
NO_ACTIVE_SQL_TRANSACTION
with message
error: ROLLBACK TO SAVEPOINT can only be used in transaction blocks\n at file:///var/task/dist/server/entry.mjs:148485:23\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async _NeonTransaction.transaction
Was this page helpful?