Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Commit 6a220a6

Browse files
authored
fix: ReadOnly transaction do not need to commit not rollback. (#2007)
1 parent 4ad7750 commit 6a220a6

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

dev/src/transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ export class Transaction implements firestore.Transaction {
509509
* @internal
510510
*/
511511
async rollback(): Promise<void> {
512-
if (!this._transactionId) {
512+
if (!this._transactionId || this._readOnly) {
513513
return;
514514
}
515515

@@ -605,7 +605,7 @@ export class Transaction implements firestore.Transaction {
605605
);
606606
}
607607
const result = await promise;
608-
if (!this._readTime) {
608+
if (!this._readOnly) {
609609
await this.commit();
610610
}
611611
return result;

dev/test/transaction.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,7 @@ describe('transaction operations', () => {
780780
async (transaction, docRef) => {
781781
transaction.set(docRef, {foo: 'bar'});
782782
},
783-
begin({readOnly: {}}),
784-
rollback()
783+
begin({readOnly: {}})
785784
)
786785
).to.eventually.be.rejectedWith(
787786
'Firestore read-only transactions cannot execute writes.'
@@ -824,8 +823,7 @@ describe('transaction operations', () => {
824823
{readOnly: true},
825824
(transaction, docRef) => transaction.get(docRef),
826825
begin({readOnly: {}}),
827-
getDocument(),
828-
commit()
826+
getDocument()
829827
);
830828
});
831829

0 commit comments

Comments
 (0)