firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.54k stars 3.93k forks source link

🐛 [cloud_firestore] Collection Group Query returns a document that does not actually exist on my Firestore database #8200

Closed Daeon97 closed 2 years ago

Daeon97 commented 2 years ago

Bug report

Describe the bug I am making a one time read collection group query with about three where clauses attached to it. The problem is that i am getting back a document that does not actually exist on my Firestore database.

Sample project

For some weird reason, in my little function

Future<QueryDocumentSnapshot<Map<String, dynamic>>?>
      userHadSearchedForThisPreviously({
    required String userId,
    required models.AutocompleteSearchResult autocompleteSearchResult,
  }) async {
final result = await _firestore
        .collectionGroup('search_history')
        .where(
          'name',
          isEqualTo: autocompleteSearchResult.name,
        )
        .where(
          'address',
          isEqualTo: autocompleteSearchResult.address,
        )
        .where(
          'geo_point',
          isEqualTo: GeoPoint(
            autocompleteSearchResult.latitude,
            autocompleteSearchResult.longitude,
          ),
        )
        .get();
    if (result.docs.isNotEmpty) {
      return result.docs[utils.nil.toInt()];
    } else {
      return null;
    }
}

When i pass a specific AutocompleteSearchResult that clearly does not actually exist in the search_history subcollection inside the users collection on my Firestore database the statement inside the if block is executed. I tried using breakpoints to examine the problem and i'm seeing a document ID that does not even exist on my Firestore database

Additional context

At the time of raising this issue I observed that some specific values fed to AutocompleteSearchResult is causing this problem. Just speculating here but i think this issue has something to do with #1722


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` engels@engels:~$ flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 2.10.2, on Ubuntu 21.10 5.13.0-30-generic, locale en_US.UTF-8) [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0-rc1) [✓] Chrome - develop for the web [✓] Android Studio (version 2020.3) [✓] Android Studio (version 2020.3) [✓] VS Code (version 1.64.2) [✓] Connected device (2 available) [✓] HTTP Host Availability • No issues found! ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` engels@engels:~/Projects/trip_rider$ flutter pub deps -- --style=compact Dart SDK 2.16.1 Flutter SDK 2.10.2 trip_rider 1.0.3+4 dependencies: - bloc 8.0.3 [meta] - cloud_firestore 3.1.10 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - cloud_functions 3.2.9 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter] - cupertino_icons 1.0.4 - equatable 2.0.3 [collection meta] - firebase_analytics 8.3.4 [firebase_analytics_platform_interface firebase_analytics_web firebase_core flutter meta] - firebase_auth 3.3.9 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 1.13.1 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_messaging 11.2.8 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - firebase_storage 10.2.9 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter] - flutter 0.0.0 [characters collection material_color_utilities meta typed_data vector_math sky_engine] - flutter_bloc 8.0.1 [flutter bloc provider] - flutter_countdown_timer 4.1.0 [flutter] - flutter_local_notifications 9.3.3 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone] - flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path typed_data vector_math] - flutter_native_splash 2.0.5 [args image js meta path xml yaml universal_io flutter flutter_web_plugins] - font_awesome_flutter 9.2.0 [flutter] - geolocator 8.2.0 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows] - google_maps_flutter 2.1.1 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface] - image_picker 0.8.4+10 [flutter flutter_plugin_android_lifecycle image_picker_for_web image_picker_platform_interface] - intl 0.17.0 [clock path] - intl_phone_number_input 0.7.0+2 [flutter meta libphonenumber_plugin equatable collection] - path_drawing 0.5.1+1 [vector_math meta path_parsing flutter] - permission_handler 8.3.0 [flutter meta permission_handler_platform_interface] - pin_code_fields 7.3.0 [flutter] - platform 3.1.0 - shared_preferences 2.0.13 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - shimmer 2.0.0 [flutter] dev dependencies: - flutter_launcher_icons 0.9.2 [args image path yaml] - flutter_lints 1.0.4 [lints] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph typed_data] transitive dependencies: - archive 3.2.1 [crypto path] - args 2.3.0 - async 2.8.2 [collection meta] - boolean_selector 2.1.0 [source_span string_scanner] - characters 1.2.0 - charcode 1.3.1 - clock 1.1.0 - cloud_firestore_platform_interface 5.5.1 [collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 2.6.10 [cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - cloud_functions_platform_interface 5.1.1 [firebase_core flutter meta plugin_platform_interface] - cloud_functions_web 4.2.9 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - collection 1.15.0 - cross_file 0.3.2 [flutter js meta] - crypto 3.0.1 [collection typed_data] - dbus 0.7.1 [args ffi meta xml] - fake_async 1.2.0 [clock collection] - ffi 1.1.2 - file 6.1.2 [meta path] - firebase 9.0.2 [http http_parser js] - firebase_analytics_platform_interface 2.0.1 [flutter meta] - firebase_analytics_web 0.3.0+1 [firebase firebase_analytics_platform_interface flutter flutter_web_plugins meta] - firebase_auth_platform_interface 6.2.1 [firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 3.3.9 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta] - firebase_core_platform_interface 4.2.5 [collection flutter meta plugin_platform_interface] - firebase_core_web 1.6.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_messaging_platform_interface 3.2.1 [firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 2.2.9 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - firebase_storage_platform_interface 4.1.1 [collection firebase_core flutter meta plugin_platform_interface] - firebase_storage_web 3.2.10 [async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta] - flutter_local_notifications_linux 0.4.2 [flutter flutter_local_notifications_platform_interface dbus path xdg_directories] - flutter_local_notifications_platform_interface 5.0.0 [flutter plugin_platform_interface] - flutter_plugin_android_lifecycle 2.0.5 [flutter] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta typed_data vector_math] - geolocator_android 3.1.0 [flutter geolocator_platform_interface] - geolocator_apple 2.1.1+1 [flutter geolocator_platform_interface] - geolocator_platform_interface 4.0.3 [flutter plugin_platform_interface vector_math meta] - geolocator_web 2.1.4 [flutter flutter_web_plugins geolocator_platform_interface] - geolocator_windows 0.1.0 [flutter geolocator_platform_interface] - google_maps_flutter_platform_interface 2.1.5 [collection flutter plugin_platform_interface stream_transform] - http 0.13.4 [async http_parser meta path] - http_parser 4.0.0 [charcode collection source_span string_scanner typed_data] - image 3.1.3 [archive meta xml] - image_picker_for_web 2.1.6 [flutter flutter_web_plugins image_picker_platform_interface] - image_picker_platform_interface 2.4.4 [cross_file flutter http plugin_platform_interface] - js 0.6.3 - libphonenumber 2.0.2 [flutter meta] - libphonenumber_platform_interface 0.3.1 [flutter plugin_platform_interface] - libphonenumber_plugin 0.2.3 [flutter flutter_web_plugins libphonenumber_platform_interface libphonenumber_web libphonenumber] - libphonenumber_web 0.2.0+1 [flutter flutter_web_plugins js libphonenumber_platform_interface] - lints 1.0.1 - matcher 0.12.11 [stack_trace] - material_color_utilities 0.1.3 - meta 1.7.0 - nested 1.0.0 [flutter] - path 1.8.0 - path_parsing 0.2.1 [vector_math meta] - path_provider_linux 2.1.5 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.0.3 [flutter platform plugin_platform_interface] - path_provider_windows 2.0.5 [ffi flutter path path_provider_platform_interface win32] - permission_handler_platform_interface 3.7.0 [flutter meta plugin_platform_interface] - petitparser 4.4.0 [meta] - plugin_platform_interface 2.1.2 [meta] - process 4.2.4 [file path platform] - provider 6.0.2 [collection flutter nested] - shared_preferences_android 2.0.11 [flutter shared_preferences_platform_interface] - shared_preferences_ios 2.1.0 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.1.0 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_macos 2.0.3 [flutter shared_preferences_platform_interface] - shared_preferences_platform_interface 2.0.0 [flutter] - shared_preferences_web 2.0.3 [flutter flutter_web_plugins shared_preferences_platform_interface] - shared_preferences_windows 2.1.0 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - sky_engine 0.0.99 - source_span 1.8.1 [collection path term_glyph] - stack_trace 1.10.0 [path] - stream_channel 2.1.0 [async] - stream_transform 2.0.0 - string_scanner 1.1.0 [charcode source_span] - term_glyph 1.2.0 - test_api 0.4.8 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - timezone 0.8.0 [path] - typed_data 1.3.0 [collection] - universal_io 2.0.4 [collection crypto meta typed_data] - vector_math 2.1.1 - win32 2.4.1 [ffi] - xdg_directories 0.2.0+1 [meta path process] - xml 5.3.1 [collection meta petitparser] - yaml 3.1.0 [collection source_span string_scanner] ```

darshankawar commented 2 years ago

@Daeon97

Can you try to use getDocuments() instead of .get() and see if it helps ? If not, Can you provide a minimal complete reproducible code sample that we can directly use and run to verify this behavior ?

google-oss-bot commented 2 years ago

Hey @Daeon97. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 2 years ago

Since there haven't been any recent updates here, I am going to close this issue.

@Daeon97 if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.