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.66k stars 3.96k forks source link

🐛 [CLOUD_FIRESTORE] Link for creating index not provided in error message #12476

Open Ituking opened 6 months ago

Ituking commented 6 months ago

Bug report

Describe the bug As described in the documentation, if the required index doesn't exist for your query, an error message with a link to create the index should be displayed in your console.

When I encounter this error, no link for creating the index is provided.

Steps to reproduce

Steps to reproduce the behavior:

  1. Setup a Flutter app and connect it to a Firebase project
  2. Create a collection called 'posts' in Firestore
  3. Add some documents to each collection. For each post document, add a timestamp field called 'created_time'
  4. Query the Collection 'posts' and order the results by 'created_time' FirebaseFirestore.instance .collection('posts') .orderBy('created_time', descending: true).get();
  5. Attempt to delete the cache using the data from the above query.
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/foundation.dart';

class CacheManager {
  Future<void> clearCache() async {
    try {
      await FirebaseFirestore.instance.clearPersistence();
      if (kDebugMode) {
        print("ローカルキャッシュが正常にクリアされました");
      }
    } catch (e) {
      if (kDebugMode) {
        print("ローカルキャッシュのクリア中にエラーが発生しました: $e");
      }
      throw Exception("ローカルキャッシュのクリアエラー: $e");
    }
  }
}

Because there is no index for this Collection query, the UI should not render. At this point the error message with the link to generate the index should appear in the console but it doesn't.

The index for this example should look like this: スクリーンショット 2024-03-12 23 27 00

Expected behavior

An error message would be generated with a link to create the Collection query.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.16.3, on macOS 14.3.1 23D60 darwin-x64, locale ja-JP) [✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) [✓] Xcode - develop for iOS and macOS (Xcode 15.3) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.2) [✓] VS Code (version 1.86.2) [✓] Connected device (3 available) [✓] Network resources • No issues found! ```

Flutter dependencies

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

Click To Expand ``` Dart SDK 3.2.3 Flutter SDK 3.16.3 feed_app 1.0.0+1 dependencies: - cloud_firestore 4.13.6 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - cupertino_icons 1.0.6 - firebase_auth 4.15.2 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 2.24.2 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_storage 11.6.0 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math web sky_engine] - image_picker 1.0.5 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_linux image_picker_macos image_picker_platform_interface image_picker_windows] - intl 0.18.1 [clock meta path] - provider 6.1.1 [collection flutter nested] dev dependencies: - flutter_lints 2.0.3 [lints] - flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math async boolean_selector characters collection material_color_utilities meta source_span stream_channel string_scanner term_glyph web] transitive dependencies: - _flutterfire_internals 1.3.16 [collection firebase_core firebase_core_platform_interface flutter meta] - async 2.11.0 [collection meta] - boolean_selector 2.1.1 [source_span string_scanner] - characters 1.3.0 - clock 1.1.1 - cloud_firestore_platform_interface 6.0.10 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 3.8.10 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - collection 1.18.0 - cross_file 0.3.3+8 [meta web] - fake_async 1.3.1 [clock collection] - file_selector_linux 0.9.2+1 [cross_file file_selector_platform_interface flutter] - file_selector_macos 0.9.3+3 [cross_file file_selector_platform_interface flutter] - file_selector_platform_interface 2.6.1 [cross_file flutter http plugin_platform_interface] - file_selector_windows 0.9.3+1 [cross_file file_selector_platform_interface flutter] - firebase_auth_platform_interface 7.0.8 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 5.8.11 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser js meta] - firebase_core_platform_interface 5.0.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.10.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_storage_platform_interface 5.1.3 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_storage_web 3.6.17 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta] - flutter_plugin_android_lifecycle 2.0.17 [flutter] - flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math web] - http 1.1.2 [async http_parser meta web] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - image_picker_android 0.8.9+1 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface] - image_picker_for_web 3.0.1 [flutter flutter_web_plugins image_picker_platform_interface mime] - image_picker_ios 0.8.9 [flutter image_picker_platform_interface] - image_picker_linux 0.2.1+1 [file_selector_linux file_selector_platform_interface flutter image_picker_platform_interface] - image_picker_macos 0.2.1+1 [file_selector_macos file_selector_platform_interface flutter image_picker_platform_interface] - image_picker_platform_interface 2.9.1 [cross_file flutter http plugin_platform_interface] - image_picker_windows 0.2.1+1 [file_selector_platform_interface file_selector_windows flutter image_picker_platform_interface] - js 0.6.7 [meta] - lints 2.1.1 - matcher 0.12.16 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.5.0 [collection] - meta 1.10.0 - mime 1.0.4 - nested 1.0.0 [flutter] - path 1.8.3 - plugin_platform_interface 2.1.7 [meta] - sky_engine 0.0.99 - source_span 1.10.0 [collection path term_glyph] - stack_trace 1.11.1 [path] - stream_channel 2.1.2 [async] - string_scanner 1.2.0 [source_span] - term_glyph 1.2.1 - test_api 0.6.1 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph] - typed_data 1.3.2 [collection] - vector_math 2.1.4 - web 0.3.0 ```

Lyokone commented 6 months ago

@Ituking what happens in this case? Is there an error message without the link? Is there no issues?

Ituking commented 6 months ago

@Lyokone Yes. I get an error message without a link. Here is the error message. I am aware that the link will appear as originally described in the documentation.

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: error clearing local cache: [cloud_firestore/failed- precondition] Operation was rejected because the system is not in a state required for the operation's execution. If performing a query, ensure it has been indexed via the Firebase console.
Lyokone commented 6 months ago

I've tried to run it in our Firestore example app without issue using live data which already has the data indexed. Can it be that you need to create the index first before clearing local persistence?


Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
  FirebaseFirestore.instance.settings = const Settings(
    persistenceEnabled: true,
  );
  if (shouldUseFirestoreEmulator) {
    FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080);
  }

  await FirebaseFirestore.instance.clearPersistence();

  runApp(FirestoreExampleApp());
}
google-oss-bot commented 6 months ago

Hey @Ituking. 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!

Ituking commented 6 months ago

We recognize that this issue has been raised as an issue several times and is an event that should have been documented and the link displayed as it should.

Here is the link https://github.com/firebase/flutterfire/issues/4545 https://github.com/firebase/flutterfire/issues/7010