Skip to content

🐛 [firestore] BatchWrite.update does not implement type-safe read & write operations. #11552

Description

@paul-appliquette

Bug report

WriteBatch.update does not implement withConverter Type handling.

This seems like a bug to me since WriteBatch.set does implement withConverter Type handling, and it appears that implementing the same in the update method has been overlooked.

Some may say this should be a Feature Request rather than a Bug Report. If that turns out to be the general consensus I'll change it.

Steps to reproduce

Steps to reproduce the behavior:

  1. Use a Flutter app configured for Firestore access.
  2. Define withConverter ToFirestore & FromFirestore functions to provide type-safe read & write operations for a data class.
  3. Attempt to perform BatchWrite.set and BatchWrite.update using withConverter and supplying the relevant data Object.

Result

BatchWrite.set has no issues.
BatchWrite.update results in error "The argument type '[Object]' can't be assigned to the parameter type 'Map<String, dynamic>'."


Expected behavior

Both BatchWrite.set and BatchWrite.update using withConverter should be allowed.


Additional context

Current implementation for BatchWrite.set:

void set<T>(
  DocumentReference<T> document,
  T data, [
  SetOptions? options,
]) {
  assert(
    document.firestore == _firestore,
    'the document provided is from a different Firestore instance',
  );

  Map<String, dynamic> firestoreData;
  if (document is _JsonDocumentReference) {
    firestoreData = data as Map<String, dynamic>;
  } else {
    final withConverterDoc = document as _WithConverterDocumentReference<T>;
    firestoreData = withConverterDoc._toFirestore(data, options);
  }

  return _delegate.set(
    document.path,
    _CodecUtility.replaceValueWithDelegatesInMap(firestoreData)!,
    options,
  );
}

Current implementation for BatchWrite.update:

void update(DocumentReference document, Map<String, dynamic> data) {
  assert(
    document.firestore == _firestore,
    'the document provided is from a different Firestore instance',
  );
  return _delegate.update(
    document.path,
    _CodecUtility.replaceValueWithDelegatesInMap(data)!,
  );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform: allIssues / PRs which are for all platforms.plugin: cloud_firestoretype: enhancementNew feature or requesttype: missing-featureA feature that is supported on the underlying Firebase SDK but has not been exposed to Dart API.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions