-
Notifications
You must be signed in to change notification settings - Fork 4k
🐛 [cloud_firestore] Retrieving a document that doesn't exist while offline permanently throws an exception (and breaks apps) #10887
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
Comments
Thanks for the report. Using the code sample provided and trying to run in offline mode gave me the same reported error:
More reference on the issue: #5708 |
/cc @Lyokone |
Any update on this issue? Thousands of my users are facing this issue. |
No need to go offline, just do a |
Facing a similar error but slightly different message.
|
Could you specify what platform(s) this is occurring on? |
Web |
I'm going to need a reproduction, I've just tested the following Flutter app in Firestore example main.dart // Copyright 2020, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'firebase_options.dart';
/// Requires that a Firestore emulator is running locally.
/// See https://firebase.flutter.dev/docs/firestore/usage#emulator-usage
bool shouldUseFirestoreEmulator = false;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
if (kIsWeb) {
await FirebaseFirestore.instance
.enablePersistence(const PersistenceSettings(synchronizeTabs: true));
}
if (shouldUseFirestoreEmulator) {
FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080);
}
runApp(FirestoreExampleApp());
}
/// The entry point of the application.
///
/// Returns a [MaterialApp].
class FirestoreExampleApp extends StatelessWidget {
final collection = FirebaseFirestore.instance.collection('flutter-tests');
final doc = 'new-one';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Firestore Example App',
theme: ThemeData.dark(),
home: Scaffold(
body: Column(
children: [
const SizedBox(height: 50),
ElevatedButton(
onPressed: () async {
// 1. set device to offline, add document to cached collection
await collection.doc(doc).set({'name': 'new-one'});
print('Set in cache');
},
child: const Text('set cached doc'),
),
ElevatedButton(
onPressed: () async {
// 2. get specific document with ID from cache
final result = await collection
.doc(doc)
.get(const GetOptions(source: Source.cache));
print('LLLLL: ${result.data()}');
},
child: const Text('get cached document'),
),
],
)),
);
}
}
Steps:
Across android, ios and web, they all received the cached document. |
@russellwheatley Did you try without specifying Source? In our app and in other reports that isn't being specified and it's using the defaults. |
I didn't because in your initial post you specified with |
Hey @stx. 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! |
Since there haven't been any recent updates here, I am going to close this issue. @stx 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. |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
When attempting to get a document that doesn't exist while offline, the error below will be permanently thrown even though the cache is populated correctly, and even after returning online:
[cloud_firestore/unavailable] The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff.
This issue has been ongoing for years in a discussion @ #5708 but has not been fully identified or understood until now. Thanks to @cammoore54 here we now have reproduction steps.
We can also confirm that this is a critical app breaking issue. In our commercial app, with over a thousand instances recorded across many cloud_firestore and Flutter versions, and it prevents users from loading data.
This causes apps to break since if a user tries to log in or do anything with a new document while offline, they will receive
cloud_firestore/unavailable
, but will still receive it when going back online until the app is killed or uninstalled and reinstalled.Steps to reproduce
Credit to @cammoore54:
The below DOESN'T raise the error:
The below DOES raise the error (only when offline):
For both of the above I have confirmed that the correct data is stored in the cache when offline.
Making this call online first, then going offline doesn't cause the error but if the device is offline the first time the call is made raises the error.
Expected behavior
No error should be thrown since the cache is populated and working in offline mode.
The text was updated successfully, but these errors were encountered: