Firestore: CollectionReference.withConverter(converter).add(data) invokes converter.toFirestore twice #2173
Labels
api: firestore
Issues related to the googleapis/nodejs-firestore API.
priority: p2
Moderately-important priority. Fix may not be included in next release.
type: bug
Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
The
toFirestore
method of converter is called multiple times when adding a new document to a collection which can cause issues if the object is mutated as part of the conversion (it seems reasonable to assume it should only be called once).Similar to this client-side issue: firebase/firebase-js-sdk#3742
Environment details
@google-cloud/firestore
version: 7.9.0Steps to reproduce
Use the
.add
method on a collection ref with a converter, mutating the object:The converter would work fine for regular
set
, andupdate
methods, but.add
causes.toFirestore
to be called twice. Although it's a good idea for the converters to use immutable patterns which would avoid this, it's an easy mistake to just mutate the existing object which can cause runtime errors or data corruption and if nothing else is wasted extra work.The text was updated successfully, but these errors were encountered: