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

[cloud_firestore]: Multiple whereIn-Filters should be supported in a query #13407

Open
1 task done
CLNMR opened this issue Sep 25, 2024 · 2 comments
Open
1 task done
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. plugin: cloud_firestore type: bug Something isn't working

Comments

@CLNMR
Copy link

CLNMR commented Sep 25, 2024

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Cloud Functions

Which platforms are affected?

Android, iOS, Web

Description

When I send a query to the cloud_firestore package (v. 4.17.5) with multiple whereIn filters, I get an error that only one whereIn filter is allowed ("You cannot use 'whereIn' filters more than once.").

This is due to the assert(!hasIn, "You cannot use 'whereIn' filters more than once."); in line 768 of "cloud_firestore-4.17.5/lib/src/query.dart".

But: Firebase supports multiple whereIn filters, as long as the DNF has at most 30 OR-clauses.
This does work in the googleapis 12.0.0 package for Dart.

Resolution approach: Remove the assert mentioned above. Instead, keep count of the length of the DNF, and assert that it is not more than 30.

Reproducing the issue

Query query = _fireStore.collection(_getCollectionPath(docSetup));
query = query.where('field1', whereIn: ['1', '2']);
query = query.where('field2', whereIn: ['1', '2']);
query.get(GetOptions(source: Source.server))

Firebase Core version

2.32.0

Flutter Version

3.22.1

Relevant Log Output

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown building RecordsBuilder-[<'false}'>](state:
_ConsumerState#2a0fd):
Assertion failed:
file:///Users/.../.pub-cache/hosted/pub.dev/cloud_firestore-4.17.5/lib/src/query.dart:768:16
!hasIn
"You cannot use 'whereIn' filters more than once."

The relevant error-causing widget was:
  RecordsBuilder-[<'false}'>]
  RecordsBuilder:file:///Users/.../.../packages/univelop/lib/widgets/records/records_list_view.dart:67:12

Flutter dependencies

Expand Flutter dependencies snippet
Dart SDK 3.4.1
Flutter SDK 3.22.1
...

dependencies:
...
- firebase_auth 4.20.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_crashlytics 3.5.7 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
- firebase_messaging 14.9.4 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- firebase_storage 11.7.7 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
...

dev dependencies:
...

dependency overrides:
...

transitive dependencies:
...
- firebase_auth_mocks 0.13.0 [flutter firebase_auth firebase_core meta equatable dart_jsonwebtoken uuid firebase_auth_platform_interface mock_exceptions]
- firebase_auth_platform_interface 7.3.0 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 5.12.0 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser meta web]
- firebase_core 2.32.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_core_platform_interface 5.1.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.17.3 [firebase_core_platform_interface flutter flutter_web_plugins meta web]
- firebase_crashlytics_platform_interface 3.6.35 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_platform_interface 4.5.37 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 3.8.7 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins meta web]
- firebase_storage_platform_interface 5.1.22 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 3.9.7 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http meta web]
- firebase_ui_firestore 1.6.3 [cloud_firestore firebase_ui_localizations firebase_ui_shared flutter]
- firebase_ui_localizations 1.12.0 [flutter flutter_localizations path]
- firebase_ui_shared 1.4.1 [flutter]

Additional context and comments

No response

@CLNMR CLNMR added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Sep 25, 2024
@SelaseKay
Copy link
Contributor

I'm unable to reproduce this issue. Can you try with FF latest versions?

@SelaseKay SelaseKay added blocked: customer-response Waiting for customer response, e.g. more information was requested. plugin: cloud_firestore and removed Needs Attention This issue needs maintainer attention. labels Sep 26, 2024
@CLNMR
Copy link
Author

CLNMR commented Sep 27, 2024

I did, the problem still persists.

Here is a more complete example to reproduce the issue:

main.dart
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        home: Scaffold(
            body: Center(
          child: TextButton(
              child: Text('Click the button to test Firestore'),
              onPressed: _test),
        )));
  }

  void _test() async {
    await Firebase.initializeApp(demoProjectId: 'demo');
    Query query = FirebaseFirestore.instance.collection('collection');
    query = query.where('field1', whereIn: ['1', '2']);
    query = query.where('field2', whereIn: ['1', '2']);
    query.get();
  }
}
pubspec.yaml
name: mwe
description: "A mnwe."
publish_to: "none"

version: 1.0.0+1

environment:
  sdk: ">=3.4.1 <4.0.0"

dependencies:
  flutter:
    sdk: flutter
  cloud_firestore: ^5.4.3
  firebase_core: ^3.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. plugin: cloud_firestore type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants