Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
paul-appliquette opened this issue Sep 5, 2023 · 1 comment
Labels
platform: all Issues / PRs which are for all platforms. plugin: cloud_firestore type: enhancement New feature or request type: missing-feature A feature that is supported on the underlying Firebase SDK but has not been exposed to Dart API.

Comments

@paul-appliquette
Copy link

paul-appliquette commented Sep 5, 2023

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)!,
  );
}
@paul-appliquette paul-appliquette added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Sep 5, 2023
@paul-appliquette paul-appliquette changed the title 🐛 [PLUGIN_NAME_HERE] Your issue title here Sep 5, 2023
@darshankawar darshankawar added the triage Issue is currently being triaged. label Sep 5, 2023
@darshankawar
Copy link

Thanks for the report. Treating this as an enhancement to support set and update to support withConverter.

/cc @Lyokone

@darshankawar darshankawar added type: enhancement New feature or request plugin: cloud_firestore type: missing-feature A feature that is supported on the underlying Firebase SDK but has not been exposed to Dart API. and removed Needs Attention This issue needs maintainer attention. triage Issue is currently being triaged. type: bug Something isn't working labels Sep 5, 2023
@Lyokone Lyokone added the platform: all Issues / PRs which are for all platforms. label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: all Issues / PRs which are for all platforms. plugin: cloud_firestore type: enhancement New feature or request type: missing-feature A feature that is supported on the underlying Firebase SDK but has not been exposed to Dart API.
3 participants