From d770aa6a2616ed0535bbc2fbd2e9645da9ad18cd Mon Sep 17 00:00:00 2001 From: Jude Selase Kwashie <64037520+SelaseKay@users.noreply.github.com> Date: Wed, 2 Oct 2024 12:40:05 +0000 Subject: [PATCH] fix(cloud_firestore): remove single whereIn filter assertion (#13436) --- .../example/integration_test/query_e2e.dart | 62 +++++++++++++++++++ .../cloud_firestore/lib/src/query.dart | 1 - 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/packages/cloud_firestore/cloud_firestore/example/integration_test/query_e2e.dart b/packages/cloud_firestore/cloud_firestore/example/integration_test/query_e2e.dart index a708bc2c8011..936d30888066 100644 --- a/packages/cloud_firestore/cloud_firestore/example/integration_test/query_e2e.dart +++ b/packages/cloud_firestore/cloud_firestore/example/integration_test/query_e2e.dart @@ -3891,5 +3891,67 @@ void runQueryTests() { expect(res.docs.map((e) => e.reference), [doc2, doc3]); }); }); + + group('WhereIn Filter', () { + testWidgets('Multiple whereIn filters should not trigger an assertion', + (_) async { + try { + final collection = await initializeTest('multipe-whereIn-clause'); + + Map data = {}; + + for (int i = 1; i <= 10; i++) { + data['field$i'] = 'value$i'; + } + + await collection.doc().set(data); + + Query> query = collection; + data.forEach((field, values) { + query = query.where(field, whereIn: [values]); + }); + + await query.get(); + } on AssertionError catch (e) { + fail('Test failed due to AssertionError: $e'); + } + }); + + testWidgets( + 'Multiple whereIn filters exceeding DNF 30 clause limit should trigger an assertion', + (_) async { + try { + final collection = await initializeTest('multipe-whereIn-clause'); + + await collection.doc().set({'genre': 'fiction'}); + await collection.doc().set({'author': 'Author A'}); + + // DNF for this query = 36 (6 genres * 6 authors) exceeding the 30 clause limit + await collection.where( + 'genre', + whereIn: [ + 'fiction', + 'non-fiction', + 'fantasy', + 'science-fiction', + 'mystery', + 'thriller', + ], + ).where( + 'author', + whereIn: [ + 'Author A', + 'Author B', + 'Author C', + 'Author D', + 'Author E', + 'Author F', + ], + ).get(); + } catch (error) { + expect(error, isA()); + } + }); + }); }); } diff --git a/packages/cloud_firestore/cloud_firestore/lib/src/query.dart b/packages/cloud_firestore/cloud_firestore/lib/src/query.dart index e1ef4953bbd1..cefa3c75883f 100644 --- a/packages/cloud_firestore/cloud_firestore/lib/src/query.dart +++ b/packages/cloud_firestore/cloud_firestore/lib/src/query.dart @@ -765,7 +765,6 @@ class _JsonQuery implements Query> { } if (operator == 'in') { - assert(!hasIn, "You cannot use 'whereIn' filters more than once."); assert( !hasNotIn, "You cannot use 'in' filters with 'not-in' filters.",