Skip to content

[cloud_firestore]: Get from server immediately after a document is updated gives old cached data when snapshot is open #17352

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

Open
1 task done
rorystephenson opened this issue May 13, 2025 · 1 comment
Labels
blocked: firebase-sdk platform: android Issues / PRs which are specifically for Android. platform: ios Issues / PRs which are specifically for iOS. plugin: cloud_firestore type: bug Something isn't working

Comments

@rorystephenson
Copy link

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Core

Which platforms are affected?

iOS, Android

Description

The short version is that when a snapshot listener for a document is already open and the app calls get(GetOptions(source: Source.server)) for that document, instead of fetching fresh data from the server cloud_firestore is returning the most recently fetched snapshot data. Moreover the isFromCache and hasPendingWrites metadata values are both false. This means we do not have a way to fetch fresh data from firestore when we know that there has been updated.

I believe this is a variant of this issue: #10153. The difference being that our write is done by the backend. We have verified that the backend waits for the transaction to complete and that the mobile app waits for the backend to respond before calling get().

The linked issue has been closed as 'will not fix' using this comment as justification however this seems incorrect for the following reasons:

  1. Firestore goes to great efforts to be a strongly consistent database that guarantees that reads which happen after a transaction is committed will return the latest data. What is the point of such a guarantee if the client short-cuts it by making it impossible to actually force a fetch of fresh data from the database.
  2. The documentation for Source.server in GetOptions makes no reference to this behaviour.
  3. In fact that same documentation emphasises that the data is being fetched from the server by mentioning that failure to fetch the data will result in an error. In my testing this does not happen, I can turn the internet off and the get() request returns the latest data from the snapshot listener.
  4. The only workaround would seem to be stopping snapshots whilst performing the get(). In a large app which may listen to documents in various places for various reasons this is not feasible and amounts to maintaining a global state somewhere to make sure that snapshots are off before a given document is fetched via get() to be sure that the returned data is up to date.
  5. Even if we didn't know that the data has just been changed for our purposes we still need to get the latest version of the data as we will be updating it via the backend API and we don't want to do that from stale data. Note that making the write from the frontend is not feasible as the backend needs to do checks on the data which the frontend cannot make.

Reproducing the issue

Same as #10153

In our case the transaction is run from a backend system but the outcome is the same.

Tested on both iOS and Android.

Firebase Core version

3.13.0

Flutter Version

3.29.3

Relevant Log Output

Flutter dependencies

Expand Flutter dependencies snippet
Dart SDK 3.7.2
Flutter SDK 3.29.3
app 0.0.0

dependencies:
- app_settings 5.1.1 [flutter plugin_platform_interface]
- app_tracking_transparency 2.0.6+1 [flutter]
- appcheck 1.5.4+1 [flutter]
- appsflyer_sdk 6.15.2 [flutter]
- async 2.12.0 [collection meta]
- auto_size_text 3.0.0 [flutter]
- bloc_presentation 1.0.1 [flutter flutter_bloc nested]
- cached_network_image 3.3.1 [cached_network_image_platform_interface cached_network_image_web flutter flutter_cache_manager octo_image]
- calendar_date_picker2 1.1.7 [flutter intl]
- clevertap_plugin 3.3.1 [flutter flutter_web_plugins js]
- clock 1.1.2
- cloud_firestore 5.6.7 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- collection 1.19.1
- connectivity_plus 6.1.3 [flutter flutter_web_plugins connectivity_plus_platform_interface web meta nm collection]
- copy_with_extension 5.0.4 [meta]
- device_info_plus 11.3.3 [device_info_plus_platform_interface ffi file flutter flutter_web_plugins meta web win32 win32_registry]
- e11_common 0.0.0 [async bloc_presentation flutter flutter_bloc json_annotation]
- equatable 2.0.7 [collection meta]
- facebook_app_events 0.19.6 [flutter]
- firebase_analytics 11.4.4 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]
- firebase_app_check 0.3.2+4 [firebase_app_check_platform_interface firebase_app_check_web firebase_core firebase_core_platform_interface flutter]
- firebase_auth 5.5.1 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 3.13.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_crashlytics 4.3.4 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
- firebase_messaging 15.2.4 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- firebase_remote_config 5.4.2 [firebase_core firebase_core_platform_interface firebase_remote_config_platform_interface firebase_remote_config_web flutter]
- firebase_testlab_detector 1.0.2 [flutter plugin_platform_interface]
- firebase_ui_firestore 1.7.1 [cloud_firestore firebase_ui_localizations firebase_ui_shared flutter]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_bloc 8.1.6 [bloc flutter provider]
- flutter_cache_manager 3.3.1 [async clock collection file flutter http path path_provider rxdart sqflite uuid]
- flutter_local_notifications 19.0.0 [clock flutter flutter_local_notifications_linux flutter_local_notifications_windows flutter_local_notifications_platform_interface timezone]
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math]
- flutter_secure_storage 9.2.4 [flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows meta]
- go_router 14.8.1 [collection flutter flutter_web_plugins logging meta]
- go_router_builder 2.8.2 [analyzer async build build_config collection meta path source_gen source_helper]
- google_api_availability 5.0.1 [flutter google_api_availability_android google_api_availability_platform_interface]
- http 1.3.0 [async http_parser meta web]
- in_app_review 2.0.10 [flutter in_app_review_platform_interface]
- infinite_scroll_pagination 4.1.0 [flutter flutter_staggered_grid_view sliver_tools]
- intl 0.19.0 [clock meta path]
- json_annotation 4.9.0 [meta]
- linked_scroll_controller 0.2.0 [flutter]
- lottie 3.3.1 [archive flutter http path vector_math]
- mask_text_input_formatter 2.9.0 [flutter]
- package_info_plus 8.3.0 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface web win32 clock]
- permission_handler 11.4.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_html permission_handler_windows permission_handler_platform_interface]
- phone_number_hint 0.0.1 [flutter flutter_web_plugins plugin_platform_interface]
- phone_numbers_parser 9.0.3 [meta]
- pinput 5.0.1 [flutter universal_platform]
- purchases_flutter 8.6.1 [flutter freezed_annotation json_annotation]
- retry 3.1.2
- rxdart 0.28.0
- shared_preferences 2.5.2 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- shimmer 3.0.0 [flutter]
- smart_auth 2.0.0 [flutter flutter_web_plugins]
- smooth_page_indicator 1.2.1 [flutter]
- timer_builder 2.0.0 [flutter]
- top_snackbar_flutter 3.2.0 [flutter]
- tutorial_coach_mark 1.2.13 [flutter]
- url_launcher 6.3.1 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- version 3.0.2

dev dependencies:
- bloc_test 9.1.7 [bloc diff_match_patch meta mocktail test]
- build_runner 2.4.15 [analyzer args async build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http http_multi_server io js logging meta mime package_config path pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web web_socket_channel yaml]
- copy_with_extension_gen 5.0.4 [analyzer build source_gen copy_with_extension meta]
- e11_analysis_options 0.0.0 [flutter_lints]
- e11_bloc_presentation_test 0.0.0 [bloc bloc_presentation diff_match_patch flutter_test meta mocktail]
- flutter_native_splash 2.4.5 [args flutter flutter_web_plugins html image meta path universal_io xml yaml ansicolor]
- 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]
- glob 2.1.3 [async collection file path string_scanner]
- integration_test 0.0.0 [flutter flutter_driver flutter_test path vm_service async boolean_selector characters clock collection fake_async file leak_tracker leak_tracker_flutter_testing leak_tracker_testing matcher material_color_utilities meta source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api vector_math webdriver]
- intl_utils 2.8.8 [analyzer archive args dart_style http intl path petitparser yaml]
- json_serializable 6.9.0 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper]
- mockingjay 0.6.0 [flutter flutter_test matcher mocktail test]
- mocktail 1.0.4 [collection matcher test_api]
- plugin_platform_interface 2.1.8 [meta]
- shared_preferences_tools 1.1.1 [flutter shared_preferences]
- url_launcher_platform_interface 2.3.2 [flutter plugin_platform_interface]

transitive dependencies:
- _fe_analyzer_shared 76.0.0 [meta]
- _flutterfire_internals 1.3.54 [collection firebase_core firebase_core_platform_interface flutter meta]
- _macros 0.3.3
- analyzer 6.11.0 [_fe_analyzer_shared collection convert crypto glob macros meta package_config path pub_semver source_span watcher yaml]
- ansicolor 2.0.3
- archive 4.0.4 [crypto path posix]
- args 2.7.0
- bloc 8.1.4 [meta]
- boolean_selector 2.1.2 [source_span string_scanner]
- build 2.4.2 [analyzer async convert crypto glob logging meta package_config path]
- build_config 1.1.2 [checked_yaml json_annotation path pubspec_parse yaml]
- build_daemon 4.0.4 [built_collection built_value crypto http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 2.4.4 [analyzer async build collection convert crypto graphs logging package_config path pool pub_semver stream_transform yaml]
- build_runner_core 8.0.0 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta package_config path pool timing watcher yaml]
- built_collection 5.1.1
- built_value 8.9.5 [built_collection collection fixnum meta]
- cached_network_image_platform_interface 4.0.0 [flutter flutter_cache_manager]
- cached_network_image_web 1.1.1 [cached_network_image_platform_interface flutter flutter_cache_manager]
- characters 1.4.0
- checked_yaml 2.0.3 [json_annotation source_span yaml]
- cloud_firestore_platform_interface 6.6.7 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 4.4.7 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins]
- code_builder 4.10.1 [built_collection built_value collection matcher meta]
- connectivity_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- convert 3.1.2 [typed_data]
- coverage 1.11.1 [args glob logging meta package_config path source_maps stack_trace vm_service]
- crypto 3.0.6 [typed_data]
- csslib 1.0.2 [source_span]
- dart_style 2.3.8 [analyzer args collection package_config path pub_semver source_span]
- dbus 0.7.11 [args ffi meta xml]
- device_info_plus_platform_interface 7.0.2 [flutter meta plugin_platform_interface]
- diff_match_patch 0.4.1
- fake_async 1.3.2 [clock collection]
- ffi 2.1.4
- file 7.0.1 [meta path]
- firebase_analytics_platform_interface 4.3.4 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_analytics_web 0.5.10+10 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins]
- firebase_app_check_platform_interface 0.1.1+4 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_app_check_web 0.2.0+8 [_flutterfire_internals firebase_app_check_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins web]
- firebase_auth_platform_interface 7.6.1 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 5.14.1 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser meta web]
- firebase_core_platform_interface 5.4.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.22.0 [firebase_core_platform_interface flutter flutter_web_plugins meta web]
- firebase_crashlytics_platform_interface 3.8.4 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_platform_interface 4.6.4 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 3.10.4 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins meta web]
- firebase_remote_config_platform_interface 1.5.2 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_remote_config_web 1.8.2 [_flutterfire_internals firebase_core firebase_core_web firebase_remote_config_platform_interface flutter flutter_web_plugins]
- firebase_ui_localizations 1.13.1 [flutter flutter_localizations path]
- firebase_ui_shared 1.4.1 [flutter]
- fixnum 1.1.1
- flutter_driver 0.0.0 [file flutter flutter_test fuchsia_remote_debug_protocol path meta vm_service webdriver async boolean_selector characters clock collection leak_tracker leak_tracker_flutter_testing leak_tracker_testing matcher material_color_utilities platform process source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api vector_math]
- flutter_lints 5.0.0 [lints]
- flutter_local_notifications_linux 6.0.0 [dbus ffi flutter flutter_local_notifications_platform_interface path xdg_directories]
- flutter_local_notifications_platform_interface 9.0.0 [plugin_platform_interface]
- flutter_local_notifications_windows 1.0.0 [flutter ffi flutter_local_notifications_platform_interface meta timezone xml]
- flutter_secure_storage_linux 1.2.2 [flutter flutter_secure_storage_platform_interface]
- flutter_secure_storage_macos 3.1.3 [flutter flutter_secure_storage_platform_interface]
- flutter_secure_storage_platform_interface 1.1.2 [flutter plugin_platform_interface]
- flutter_secure_storage_web 1.2.1 [flutter flutter_secure_storage_platform_interface flutter_web_plugins js]
- flutter_secure_storage_windows 3.1.2 [ffi flutter flutter_secure_storage_platform_interface path path_provider win32]
- flutter_staggered_grid_view 0.7.0 [flutter]
- flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math]
- freezed_annotation 2.4.4 [collection json_annotation meta]
- frontend_server_client 4.0.0 [async path]
- fuchsia_remote_debug_protocol 0.0.0 [process vm_service file meta path platform]
- google_api_availability_android 1.1.1 [flutter google_api_availability_platform_interface]
- google_api_availability_platform_interface 1.0.1 [flutter plugin_platform_interface meta]
- graphs 2.3.2 [collection]
- html 0.15.5 [csslib source_span]
- http_multi_server 3.2.2 [async]
- http_parser 4.1.2 [collection source_span string_scanner typed_data]
- image 4.5.3 [archive meta xml]
- in_app_review_platform_interface 2.0.5 [flutter url_launcher plugin_platform_interface platform]
- io 1.0.5 [meta path string_scanner]
- js 0.6.7 [meta]
- leak_tracker 10.0.8 [clock collection meta path vm_service]
- leak_tracker_flutter_testing 3.0.9 [flutter leak_tracker leak_tracker_testing matcher meta]
- leak_tracker_testing 3.0.1 [leak_tracker matcher meta]
- lints 5.1.1
- logging 1.3.0
- macros 0.1.3-main.0 [_macros]
- matcher 0.12.17 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.11.1 [collection]
- meta 1.16.0
- mime 2.0.0
- nested 1.0.0 [flutter]
- nm 0.5.0 [dbus]
- node_preamble 2.0.2
- octo_image 2.1.0 [flutter]
- package_config 2.2.0 [path]
- package_info_plus_platform_interface 3.2.0 [flutter meta plugin_platform_interface]
- path 1.9.1
- path_provider 2.1.5 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows]
- path_provider_android 2.2.16 [flutter path_provider_platform_interface]
- path_provider_foundation 2.4.1 [flutter path_provider_platform_interface]
- path_provider_linux 2.2.1 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_platform_interface 2.1.2 [flutter platform plugin_platform_interface]
- path_provider_windows 2.3.0 [ffi flutter path path_provider_platform_interface]
- permission_handler_android 12.1.0 [flutter permission_handler_platform_interface]
- permission_handler_apple 9.4.6 [flutter permission_handler_platform_interface]
- permission_handler_html 0.1.3+5 [flutter flutter_web_plugins permission_handler_platform_interface web]
- permission_handler_platform_interface 4.3.0 [flutter meta plugin_platform_interface]
- permission_handler_windows 0.2.1 [flutter permission_handler_platform_interface]
- petitparser 6.1.0 [meta collection]
- platform 3.1.6
- pool 1.5.1 [async stack_trace]
- posix 6.0.1 [ffi meta path]
- process 5.0.3 [file path platform]
- provider 6.1.2 [collection flutter nested]
- pub_semver 2.2.0 [collection]
- pubspec_parse 1.5.0 [checked_yaml collection json_annotation pub_semver yaml]
- shared_preferences_android 2.4.8 [flutter shared_preferences_platform_interface]
- shared_preferences_foundation 2.5.4 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.4.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.4.1 [flutter plugin_platform_interface]
- shared_preferences_web 2.4.3 [flutter flutter_web_plugins shared_preferences_platform_interface web]
- shared_preferences_windows 2.4.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- shelf 1.4.2 [async collection http_parser path stack_trace stream_channel]
- shelf_packages_handler 3.0.2 [path shelf shelf_static]
- shelf_static 1.1.3 [convert http_parser mime path shelf]
- shelf_web_socket 3.0.0 [shelf stream_channel web_socket_channel]
- sky_engine 0.0.0
- sliver_tools 0.2.12 [flutter]
- source_gen 1.5.0 [analyzer async build dart_style glob path source_span yaml]
- source_helper 1.3.5 [analyzer collection source_gen]
- source_map_stack_trace 2.1.2 [path source_maps stack_trace]
- source_maps 0.10.13 [source_span]
- source_span 1.10.1 [collection path term_glyph]
- sprintf 7.0.0
- sqflite 2.4.2 [flutter sqflite_android sqflite_darwin sqflite_platform_interface sqflite_common path]
- sqflite_android 2.4.1 [flutter sqflite_common path sqflite_platform_interface]
- sqflite_common 2.5.5 [synchronized path meta]
- sqflite_darwin 2.4.2 [flutter sqflite_platform_interface meta sqflite_common path]
- sqflite_platform_interface 2.4.0 [flutter platform sqflite_common plugin_platform_interface meta]
- stack_trace 1.12.1 [path]
- stream_channel 2.1.4 [async]
- stream_transform 2.1.1
- string_scanner 1.4.1 [source_span]
- sync_http 0.3.1
- synchronized 3.3.1
- term_glyph 1.2.2
- test 1.25.15 [analyzer async boolean_selector collection coverage http_multi_server io js matcher node_preamble package_config path pool shelf shelf_packages_handler shelf_static shelf_web_socket source_span stack_trace stream_channel test_api test_core typed_data web_socket_channel webkit_inspection_protocol yaml]
- test_api 0.7.4 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph]
- test_core 0.6.8 [analyzer args async boolean_selector collection coverage frontend_server_client glob io meta package_config path pool source_map_stack_trace source_maps source_span stack_trace stream_channel test_api vm_service yaml]
- timezone 0.10.0 [http path]
- timing 1.0.2 [json_annotation]
- typed_data 1.4.0 [collection]
- universal_io 2.2.2 [collection meta typed_data]
- universal_platform 1.1.0
- url_launcher_android 6.3.15 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.3.2 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.2.1 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.2.2 [flutter url_launcher_platform_interface]
- url_launcher_web 2.4.0 [flutter flutter_web_plugins url_launcher_platform_interface web]
- url_launcher_windows 3.1.4 [flutter url_launcher_platform_interface]
- uuid 4.5.1 [crypto sprintf meta fixnum]
- vector_math 2.1.4
- vm_service 14.3.1
- watcher 1.1.1 [async path]
- web 1.1.1
- web_socket 0.1.6 [web]
- web_socket_channel 3.0.2 [async crypto stream_channel web web_socket]
- webdriver 3.0.4 [matcher path stack_trace sync_http]
- webkit_inspection_protocol 1.2.1 [logging]
- win32 5.12.0 [ffi]
- win32_registry 2.1.0 [ffi meta win32]
- xdg_directories 1.1.0 [meta path]
- xml 6.5.0 [collection meta petitparser]
- yaml 3.1.3 [collection source_span string_scanner]

Additional context and comments

No response

@rorystephenson rorystephenson added type: bug Something isn't working Needs Attention This issue needs maintainer attention. labels May 13, 2025
@SelaseKay SelaseKay added plugin: cloud_firestore platform: android Issues / PRs which are specifically for Android. platform: ios Issues / PRs which are specifically for iOS. labels May 14, 2025
@SelaseKay
Copy link
Contributor

Hi @rorystephenson, thanks for the detailed report. I was able to reproduce this issue with the native SDKs which indicates this behaviour stems from the underlying SDKs. FlutterFire is simply a wrapper around the native SDKs. Given that, there's nothing much we can do on our end. I recommend you file a ticket on the native SDK repos for further investigation.

Firebase Android SDK
Firebase iOS SDK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked: firebase-sdk platform: android Issues / PRs which are specifically for Android. platform: ios Issues / PRs which are specifically for iOS. plugin: cloud_firestore type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants