Skip to content

Batches and transactions brokenΒ #37

@gmarizy

Description

@gmarizy

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions