From 13a01dee9b05fb48757e4a54840ed8d783ada7c1 Mon Sep 17 00:00:00 2001 From: Syed Osama Ali Shah <86572800+Osamaali313@users.noreply.github.com> Date: Sun, 5 Jul 2026 19:02:55 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=84=EF=B8=8F=20fix:=20Return=20Cached?= =?UTF-8?q?=20Transaction-Support=20Value=20on=20Cache=20Hit=20(#13999)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getTransactionSupport initialized transactionsSupported to false and only assigned it on a cache miss (transactionSupportCache === null), so on a cache hit it returned false regardless of the cached value. After the first bulkUpdateResourcePermissions call populated the cache with true, every later call reported false and the bulk permission writes silently stopped running inside a MongoDB transaction, losing atomicity. Return the cached boolean on a cache hit; the cache-miss path still probes via supportsTransactions. Adds a regression test. --- packages/data-schemas/src/utils/transactions.spec.ts | 11 +++++++++++ packages/data-schemas/src/utils/transactions.ts | 7 +++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 packages/data-schemas/src/utils/transactions.spec.ts diff --git a/packages/data-schemas/src/utils/transactions.spec.ts b/packages/data-schemas/src/utils/transactions.spec.ts new file mode 100644 index 0000000000..7013bd2a45 --- /dev/null +++ b/packages/data-schemas/src/utils/transactions.spec.ts @@ -0,0 +1,11 @@ +import { getTransactionSupport } from './transactions'; + +describe('getTransactionSupport', () => { + // The cache-hit path does not touch the database, so a stub mongoose is fine. + const mongoose = {} as unknown as typeof import('mongoose'); + + it('returns the cached value on a cache hit (does not re-probe)', async () => { + await expect(getTransactionSupport(mongoose, true)).resolves.toBe(true); + await expect(getTransactionSupport(mongoose, false)).resolves.toBe(false); + }); +}); diff --git a/packages/data-schemas/src/utils/transactions.ts b/packages/data-schemas/src/utils/transactions.ts index b54447ffbf..799a74e936 100644 --- a/packages/data-schemas/src/utils/transactions.ts +++ b/packages/data-schemas/src/utils/transactions.ts @@ -55,9 +55,8 @@ export const getTransactionSupport = async ( mongoose: typeof import('mongoose'), transactionSupportCache: boolean | null, ): Promise => { - let transactionsSupported = false; - if (transactionSupportCache === null) { - transactionsSupported = await supportsTransactions(mongoose); + if (transactionSupportCache !== null) { + return transactionSupportCache; } - return transactionsSupported; + return await supportsTransactions(mongoose); };