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

Batches and transactions broken #37

Open
gmarizy opened this issue Dec 8, 2024 · 0 comments · May be fixed by #38
Open

Batches and transactions broken #37

gmarizy opened this issue Dec 8, 2024 · 0 comments · May be fixed by #38

Comments

@gmarizy
Copy link
Contributor

gmarizy commented Dec 8, 2024

Expected Behavior

Batches and transactions should work

Actual Behavior

Batches and transactions fail with error like: TypeError: Instance of '(TestSerializable, SetOptions?) => Map<String, Object?>': type '(TestSerializable, SetOptions?) => Map<String, Object?>' is not a subtype of type '(Object, SetOptions?) => Map<String, Object?>'

Steps to Reproduce the Problem

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cloud_firestore_odm/cloud_firestore_odm.dart';
import 'package:json_annotation/json_annotation.dart';

part 'test.g.dart';

/// A custom JsonSerializable annotation that supports decoding objects such
/// as Timestamps and DateTimes.
/// This variable can be reused between different models
const firestoreSerializable = JsonSerializable(
  converters: firestoreJsonConverters,
  // The following values could alternatively be set inside your `build.yaml`
  explicitToJson: true,
  createFieldMap: true,
  createPerFieldToJson: true,
);

@firestoreSerializable
class TestSerializable {
  TestSerializable({
    required this.origin,
  });

  final String origin;
}

@Collection<TestSerializable>('test')
final testCollectionReference = TestSerializableCollectionReference();

test() async {
  testCollectionReference.doc("id1").set(TestSerializable(origin: 'regular'));

  final batch = FirebaseFirestore.instance.batch();
  testCollectionReference.doc("id2").batchSet(batch, TestSerializable(origin: 'batch'));
  await batch.commit();

  FirebaseFirestore.instance.runTransaction((transaction) async {
    testCollectionReference.doc("id3").transactionSet(transaction, TestSerializable(origin: 'transaction'));
  });
}
  1. Execute test() in a flutter project where Firestore is configured
  2. Verify in Firestore console that test collection contains doc id1, but no id2 or id3.

Specifications

  • Version: cloud_firestore_odm: 1.0.0-dev.88, cloud_firestore_odm_generator: 1.0.0-dev.89, cloud_firestore: 5.5.1
  • Platform: Android, web (not tested on iOS)
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

Successfully merging a pull request may close this issue.

1 participant