Skip to content

Commit 565b193

Browse files
pr requested changes
1 parent 22d73a9 commit 565b193

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Diff for: src/operations/execute_operation.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,13 @@ export async function executeOperation<
119119
const readPreference = operation.readPreference ?? ReadPreference.primary;
120120
const inTransaction = !!session?.inTransaction();
121121

122+
const hasReadAspect = operation.hasAspect(Aspect.READ_OPERATION);
123+
const hasWriteAspect = operation.hasAspect(Aspect.WRITE_OPERATION);
124+
122125
if (
123126
inTransaction &&
124127
!readPreference.equals(ReadPreference.primary) &&
125-
(operation.hasAspect(Aspect.READ_OPERATION) || operation.commandName === 'runCommand')
128+
(hasReadAspect || operation.commandName === 'runCommand')
126129
) {
127130
throw new MongoTransactionError(
128131
`Read preference in a transaction must be primary, not: ${readPreference.mode}`
@@ -181,8 +184,6 @@ export async function executeOperation<
181184
supportsRetryableWrites(server) &&
182185
operation.canRetryWrite;
183186

184-
const hasReadAspect = operation.hasAspect(Aspect.READ_OPERATION);
185-
const hasWriteAspect = operation.hasAspect(Aspect.WRITE_OPERATION);
186187
const willRetry = (hasReadAspect && willRetryRead) || (hasWriteAspect && willRetryWrite);
187188

188189
if (hasWriteAspect && willRetryWrite) {

0 commit comments

Comments
 (0)