FirebaseExtended / firestoreodm-flutter

BSD 3-Clause "New" or "Revised" License
36 stars 11 forks source link

Parsing Error on whereIn Query with Document IDs #6

Open motucraft opened 9 months ago

motucraft commented 9 months ago

Expected Behavior

Using whereIn to filter by document IDs with cloud_firestore_odm should work similarly to cloud_firestore, allowing queries to be made based on a list of document IDs without any issues.

Actual Behavior

When using whereIn with document IDs in cloud_firestore_odm, an error occurs, whereas the same operation succeeds without issues when using cloud_firestore directly.

An error occurred while parsing query arguments, this is most likely an error with this SDK. (
    0   CoreFoundation                      0x000000018048d8a8 __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x000000018008409c objc_exception_throw + 56
    2   FirebaseFirestoreInternal           0x0000000102c1f458 _ZN8firebase9firestore4util16ObjcThrowHandlerENS1_13ExceptionTypeEPKcS4_iRKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEE + 540
    3   FirebaseFirestoreInternal           0x0000000102c1ea64 _ZN8firebase9firestore4util5ThrowENS1_13ExceptionTypeEPKcS4_iRKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEE + 64
    4   FirebaseFirestoreInternal           0x0000000102cf7d54 _ZN8firebase9firestore4util20ThrowInvalidArgumentIJNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEEEEvPKcDpRKT_ + 64
    5   FirebaseFirestoreInternal           0x0000000102eda7d0 _ZNK8firebase9firestore3api5Query27ParseExpectedReferenceValueERKNS0_26_google_firestore_v1_ValueERKNSt3__18functionIFNS6_12basic_stringIcNS6_11char_traitsIcEENS6_9allocatorIcEEEEvEEE +
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [cloud_firestore/unknown] An error occurred while parsing query arguments, this is most likely an error with this SDK.
#0      FirebaseFirestoreHostApi.queryGet (package:cloud_firestore_platform_interface/src/pigeon/messages.pigeon.dart:1130:7)
<asynchronous suspension>
#1      MethodChannelQuery.get (package:cloud_firestore_platform_interface/src/method_channel/method_channel_query.dart:118:11)
<asynchronous suspension>
#2      _JsonQuery.get (package:cloud_firestore/src/query.dart:432:9)
<asynchronous suspension>
#3      _WithConverterQuery.get (package:cloud_firestore/src/query.dart:983:22)
<asynchronous suspension>
#4      IssueQuerySnapshot.IssueQuerySnapshot._fromQuerySnapshot (package:firebase_playground/issue.g.dart:754:3)
<asynchronous suspension>
#5      MyApp.build.<anonymous closure> (package:firebase_playground/issue.dart:38:7)
<asynchronous suspension>

Steps to Reproduce the Problem

  1. Execute following example
  2. Attempt to query documents by their IDs using whereIn with the issuesRef.whereDocumentId(whereIn: ['1', '3']).get() function.
  3. This leads to the display of the previously mentioned error message.
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cloud_firestore_odm/cloud_firestore_odm.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_playground/firebase_options.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'issue.freezed.dart';
part 'issue.g.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    // OK: cloud_firestore
    Future.microtask(() async {
      final collection = FirebaseFirestore.instance.collection('issues');
      final querySnapshot = await collection
          .where(FieldPath.documentId, whereIn: ['1', '3']).get();
      querySnapshot.docs.forEach((element) {
        print('data=${element.data()}');
      });
    });

    // NG: cloud_firestore_odm
    Future.microtask(() async {
      await issuesRef.whereDocumentId(whereIn: ['1', '3']).get();
    });

    return const MaterialApp(
        home: Scaffold(body: Center(child: Text('issues'))));
  }
}

@freezed
class Issue with _$Issue {
  const factory Issue({
    required String id,
  }) = _Issue;

  factory Issue.fromJson(Map<String, Object?> json) => _$IssueFromJson(json);
}

@Collection<Issue>('issues')
final issuesRef = IssueCollectionReference();

IssueDocumentReference issueRef({required String id}) =>
    IssueDocumentReference(issuesRef.doc(id).reference);

collection is as follows:

Specifications

flutter doctor -v ``` % flutter doctor -v [✓] Flutter (Channel stable, 3.16.9, on macOS 14.3.1 23D60 darwin-arm64, locale ja-JP) • Flutter version 3.16.9 on channel stable at /Users/osaki/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 41456452f2 (2 weeks ago), 2024-01-25 10:06:23 -0800 • Engine revision f40e976bed • Dart version 3.2.6 • DevTools version 2.28.5 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2) • Android SDK at /Users/osaki/Library/Android/sdk • Platform android-33, build-tools 33.0.2 • Java binary at: /Users/osaki/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.2) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15C500b • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.1) • Android Studio at /Users/osaki/Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) [✓] IntelliJ IDEA Ultimate Edition (version 2023.3.3) • IntelliJ at /Users/osaki/Applications/IntelliJ IDEA Ultimate.app • Flutter plugin version 77.3.1 • Dart plugin version 233.13763.5 [✓] VS Code (version 1.86.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension can be installed from: 🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [✓] Connected device (4 available) • motucraft (mobile) • 00008130-001A34290CC2001C • ios • iOS 17.3.1 21D61 • iPhone 15 Pro Max (mobile) • 34AAA87A-1E84-4717-A688-316247843A52 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.3.1 23D60 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 121.0.6167.160 [✓] Network resources • All expected network resources are available. • No issues found! ```
motucraft commented 9 months ago

@rrousselGit I believe the functionality was working fine in version 1.0.0-dev.80. Could this be an issue related to the version upgrade? The following versions functioned properly.

  cloud_firestore: ^4.13.5
  cloud_firestore_odm: ^1.0.0-dev.80
motucraft commented 8 months ago

@rrousselGit Is it the same cause as https://github.com/FirebaseExtended/firestoreodm-flutter/commit/a838434bd75d270611b2a8b3848d0113758431d6 ? If same, close this.

gmarizy commented 8 months ago

Dev version 83 is flawed, see https://github.com/FirebaseExtended/firestoreodm-flutter/issues/7

Try with latest versions:

cloud_firestore: 4.15.8
cloud_firestore_odm: 1.0.0-dev.84
cloud_firestore_odm_generator: 1.0.0-dev.85

You can test with those versions, and close this issue yourself if it's the case.