Skip to content

Commit

Permalink
fix: ReadOnly transaction do not need to commit not rollback. (#2007)
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-andersen committed Mar 6, 2024
1 parent 4ad7750 commit 6a220a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions dev/src/transaction.ts
Expand Up @@ -509,7 +509,7 @@ export class Transaction implements firestore.Transaction {
* @internal
*/
async rollback(): Promise<void> {
if (!this._transactionId) {
if (!this._transactionId || this._readOnly) {
return;
}

Expand Down Expand Up @@ -605,7 +605,7 @@ export class Transaction implements firestore.Transaction {
);
}
const result = await promise;
if (!this._readTime) {
if (!this._readOnly) {
await this.commit();
}
return result;
Expand Down
6 changes: 2 additions & 4 deletions dev/test/transaction.ts
Expand Up @@ -780,8 +780,7 @@ describe('transaction operations', () => {
async (transaction, docRef) => {
transaction.set(docRef, {foo: 'bar'});
},
begin({readOnly: {}}),
rollback()
begin({readOnly: {}})
)
).to.eventually.be.rejectedWith(
'Firestore read-only transactions cannot execute writes.'
Expand Down Expand Up @@ -824,8 +823,7 @@ describe('transaction operations', () => {
{readOnly: true},
(transaction, docRef) => transaction.get(docRef),
begin({readOnly: {}}),
getDocument(),
commit()
getDocument()
);
});

Expand Down

0 comments on commit 6a220a6

Please sign in to comment.