Skip to content

Commit 84d6e49

Browse files
Remove asserts again
1 parent ebf7fbf commit 84d6e49

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

packages/firestore/src/model/document.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class MutableDocument implements Document {
259259

260260
setHasCommittedMutations(): MutableDocument {
261261
debugAssert(
262-
!this.isValidDocument(),
262+
this.isValidDocument(),
263263
'Invalid documents cannot have committed mutations'
264264
);
265265
this.documentState = DocumentState.HAS_COMMITTED_MUTATIONS;

packages/firestore/src/model/mutation.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,11 @@ function applySetMutationToLocalView(
410410
document: MutableDocument,
411411
localWriteTime: Timestamp
412412
): void {
413-
debugAssert(
414-
mutation.precondition.isNone,
415-
'SetMutations should not have preconditions outside of Transactions'
416-
);
413+
if (!preconditionIsValidForDocument(mutation.precondition, document)) {
414+
// The mutation failed to apply (e.g. a document ID created with add()
415+
// caused a name collision).
416+
return;
417+
}
417418

418419
const newData = mutation.value.clone();
419420
const transformResults = localTransformResults(
@@ -626,14 +627,11 @@ function applyDeleteMutationToLocalView(
626627
document.key.isEqual(mutation.key),
627628
'Can only apply mutation to document with same key'
628629
);
629-
debugAssert(
630-
mutation.precondition.isNone,
631-
'DeleteMutions should not have preconditions outside of Transactions'
632-
);
633-
634-
// We don't call `setHasLocalMutations()` since we want to be backwards
635-
// compatible with the existing SDK behavior.
636-
document.convertToNoDocument(SnapshotVersion.min());
630+
if (preconditionIsValidForDocument(mutation.precondition, document)) {
631+
// We don't call `setHasLocalMutations()` since we want to be backwards
632+
// compatible with the existing SDK behavior.
633+
document.convertToNoDocument(SnapshotVersion.min());
634+
}
637635
}
638636

639637
/**

0 commit comments

Comments
 (0)