[cloud_firestore]: Data Dropped On Permission Denied
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
调研方向
使用 issue 中所示的规则,通过 Firebase.initializeApp、FirebaseFirestore.instance、disableNetwork 和 collection.add 重现该场景。跟踪发生 permission-denied 错误后离线写入的情况。完成的标准是:三个文档(包括在离线状态或被拒绝期间执行的写入)仍然可用,并在权限恢复后上传。
由索引模型根据 Issue 内容生成。
描述
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
No response
Which platforms are affected?
No response
Description
We ran into a scenario where a device was offline and the permissions for collection changed. Subsequently, when back online and an attempt to upload the data was made, a
E/flutter (20761): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.
error was received and the data that was never uploaded to firestore was dropped and lost forever. We verified this behavior through local testing.
The expected behavior would be to never remove any local data unless explicitly told to.
Reproducing the issue
Run
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
FirebaseFirestore.instance.settings =
const Settings(persistenceEnabled: true, cacheSizeBytes: Settings.CACHE_SIZE_UNLIMITED);
final db = FirebaseFirestore.instance;
final collection = db.collection("t");
await db.disableNetwork();
collection.add({"0": 0});
await Future.delayed(const Duration(milliseconds: 1000));
Then change the rules to
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
Wait a few moments for the new rules to take effect. Then run the previous code again with await db.disableNetwork(); commented out and change {"0": 0} -> {"1": 0}. You will get the permission denied error.
Then change the rules to:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
and run the code again but change {"1": 0} -> {"2": 0}
The expect result would be three documents in the "t" collection, with data {"0": 0}, {"1": 0} and {"2": 0}. But when following the above steps, only {"2": 0} actually exists.
Firebase Core version
3.3.0
Flutter Version
3.22.3
Relevant Log Output
No response
Flutter dependencies
Expand Flutter dependencies snippet
Dart SDK 3.4.4
Flutter SDK 3.22.3
firebase_offline_test 1.0.0+1
dependencies:
- cloud_firestore 5.2.0 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 3.3.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
dev dependencies:
- flutter_lints 3.0.2 [lints]
- flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing async boolean_selector characters collection leak_tracker leak_tracker_testing material_color_utilities meta source_span stream_channel string_scanner term_glyph vm_service]
transitive dependencies:
- _flutterfire_internals 1.3.40 [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.3.0 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 4.1.0 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins]
- collection 1.18.0
- fake_async 1.3.1 [clock collection]
- firebase_core_platform_interface 5.2.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.17.4 [firebase_core_platform_interface flutter flutter_web_plugins meta web]
- flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math]
- leak_tracker 10.0.4 [clock collection meta path vm_service]
- leak_tracker_flutter_testing 3.0.3 [flutter leak_tracker leak_tracker_testing matcher meta]
- leak_tracker_testing 3.0.1 [leak_tracker matcher meta]
- lints 3.0.0
- matcher 0.12.16+1 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.8.0 [collection]
- meta 1.12.0
- path 1.9.0
- plugin_platform_interface 2.1.8 [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.7.0 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph]
- vector_math 2.1.4
- vm_service 14.2.1
- web 0.5.1
Additional context and comments
No response
- 主要语言
- Dart
- 星标
- 9.3k
- 派生
- 4.1k
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 69
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
firebase/flutterfire 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
firebase/flutterfire#18918 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
firebase/flutterfire#18908 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 67/100
firebase/flutterfire#18917 ·
维护者通常 1 天内回复
-
[📚] App Check Windows Support still N/A on Readme可能已有人在做 @Adrianogba 于 2 天前认领。 未关闭good first issue type: documentation
难度 1/5 1 小时以内 新手友好度 35/100
firebase/flutterfire#18913 ·
维护者通常 1 天内回复
-
[📚] Data Connect Windows Support still N/A on Readme可能已有人在做 @Adrianogba 于 2 天前认领。 未关闭good first issue type: documentation
难度 1/5 1 小时以内 新手友好度 35/100
firebase/flutterfire#18911 ·
维护者通常 1 天内回复
查看 firebase/flutterfire 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
ccch1mneyyy/dsh-Go#731 ·
维护者通常 1 天内回复
-
enhancement good first issue help wanted
难度 2/5 1-3 小时 新手友好度 88/100
-
bug
难度 2/5 1-3 小时 新手友好度 62/100
berkmancenter/frankly#753 ·
维护者通常 4 天内回复
-
good first issue mobile translation-km
难度 2/5 1-3 小时 新手友好度 92/100
NemSothea/LifeLinkKh#66 ·
维护者通常 4 天内回复