© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
4 replies
san4d

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
        }
    }
}
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
        }
    }
}
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
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
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Transactions with postgres
Drizzle TeamDTDrizzle Team / help
3y ago
Unit Testing with Transactions
Drizzle TeamDTDrizzle Team / help
3y ago
[SOLVED] Issue with Postgres transactions
Drizzle TeamDTDrizzle Team / help
17mo ago
Inconsistent transactions with Drizzle/Planetscale
Drizzle TeamDTDrizzle Team / help
3y ago