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

Batch operations fail when listening to document changes #223

Open
ccrusius opened this issue Apr 15, 2022 · 0 comments
Open

Batch operations fail when listening to document changes #223

ccrusius opened this issue Apr 15, 2022 · 0 comments

Comments

@ccrusius
Copy link

(May be a duplicate of #182.)

When I batch create two documents while listening for document changes I see null document data coming in. The following test fails:

import 'package:fake_cloud_firestore/fake_cloud_firestore.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  test('Batch with doc change subscription', () async {
    final db = FakeFirebaseFirestore();
    final sub = db.collection('docs').snapshots().listen((querySnapshot) {
      for (final change in querySnapshot.docChanges) {
        debugPrint(
            'Change: ${change.doc.id} ${change.type} ${change.doc.data()}');
      }
    });
    addTearDown(sub.cancel);

    final batch = db.batch();
    batch.set(db.collection('docs').doc('1'), <String, dynamic>{});
    batch.set(db.collection('docs').doc('2'), <String, dynamic>{});
    await batch.commit();
    await pumpEventQueue();
  });
}

with

Change: 1 DocumentChangeType.added null
Change: 2 DocumentChangeType.added null
package:fake_cloud_firestore/src/mock_query_document_snapshot.dart 16:27  MockQueryDocumentSnapshot.data
package:fake_cloud_firestore/src/fake_query_with_parent.dart 45:27        _snapshotEquals
... (snip) ...
Null check operator used on a null value

This works if changes are non-batched, or if there's no listen in place. Tried with latest master, fails there too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant