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.68k stars 3.97k forks source link

🐛 [cloud_firestore 0.14.0+2] Transactions swallow permission errors #3458

Closed larssn closed 4 years ago

larssn commented 4 years ago

Bug report

Describe the bug I was having trouble with a transaction that ran to completion every time, but no data was updated. Turns out one of my security rules was blocking one of the writes in the transaction, but no indication of this ever reached my code.

I haven't tested if it happens with single write transactions.

Steps to reproduce

Perform a transaction, something like:

import 'package:cloud_firestore/cloud_firestore.dart';

createData() async {
  final fs = FirebaseFirestore.instance;

  await fs.doc('test/doc1').set({
    'hello': 'world',
  });

  await fs.doc('test/doc2').set({
    'hello': 'world',
  });
}

test() async {
  final fs = FirebaseFirestore.instance;

  await fs.runTransaction((trx) async {
    final readwrite = fs.doc('test/doc1');
    final readonly = fs.doc('test/doc2');

    // Lock the required references.
    await trx.get(readwrite);
    await trx.get(readonly);

    // Update doc1
    await trx.set(readwrite, {'wasUpdated': true}, SetOptions(merge: true));
    // alternative way
    // await trx.update(readwrite, {'wasUpdated': true});

    // Update doc2
    await trx.delete(readonly);
    // alternative way
    // await trx.update(readonly, {'wasUpdated': true});
  });
}

Security rules:

match /test/doc1 {
   allow read, write: if request.auth != null;
}
match /test/doc2 {
   allow read, write: if request.auth != null;
}

Run createData(), then remove the doc2 security rule.

Notice how the permission error never shows up.

Expected behavior

I expect errors to bubble up correctly.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` [✓] Flutter (Channel stable, 1.20.2, on Mac OS X 10.13.6 17G14019, locale en-DK) [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2) [!] Xcode - develop for iOS and macOS ✗ Xcode installation is incomplete; a full installation is necessary for iOS development. Download at: https://developer.apple.com/xcode/download/ Or install Xcode via the App Store. Once installed, run: sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer sudo xcodebuild -runFirstLaunch [✓] Android Studio (version 4.0) [✓] VS Code (version 1.48.2) [✓] Connected device (1 available) ```

Flutter dependencies

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

Click To Expand ``` dependencies: - animated_text_kit 2.2.0 [flutter] - audioplayers 0.15.1 [uuid path_provider flutter flutter_web_plugins] - bloc 6.0.2 [meta] - built_collection 4.3.2 [collection quiver] - built_value 7.1.0 [built_collection collection fixnum quiver] - cached_network_image 2.2.0+1 [flutter flutter_cache_manager] - charts_flutter 0.9.0 [charts_common collection flutter intl logging meta] - cloud_firestore 0.14.0+2 [flutter meta quiver firebase_core firebase_core_platform_interface cloud_firestore_platform_interface cloud_firestore_web] - country_code_picker 1.4.0 [flutter] - country_pickers 1.3.0 [flutter] - crypto 2.1.5 [collection convert typed_data] - cupertino_icons 0.1.3 - dart_date 1.0.7 [intl timeago] - data_connection_checker 0.3.4 - device_info 0.4.2+7 [flutter device_info_platform_interface] - firebase_auth 0.18.0+1 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter] - firebase_core 0.5.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web] - firebase_crashlytics 0.1.4+1 [flutter stack_trace] - firebase_dynamic_links 0.6.0 [flutter firebase_core] - firebase_storage 4.0.0 [flutter firebase_core] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_bloc 6.0.1 [flutter bloc provider] - flutter_cupertino_localizations 1.0.1 [flutter flutter_localizations] - flutter_dotenv 2.1.0 [flutter meta] - flutter_localizations 0.0.0 [flutter intl characters collection meta path typed_data vector_math] - flutter_material_color_picker 1.0.5 [flutter] - flutter_nfc_acs 0.1.6 [flutter flutter_plugin_android_lifecycle] - flutter_slidable 0.5.5 [flutter] - flutter_vibrate 1.0.0 [flutter] - http 0.12.2 [http_parser path pedantic] - image 2.1.14 [archive xml] - image_picker 0.6.7+6 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface] - intl 0.16.1 [path] - nfc_in_flutter 2.0.5 [flutter] - package_info 0.4.3 [flutter] - phone_number 0.6.2+4 [flutter] - positioned_tap_detector 1.0.3 [flutter] - provider 4.3.2+1 [flutter nested collection] - random_string 2.1.0 - reorderables 0.3.2 [flutter] - rxdart 0.24.1 - sentry 3.0.1 [http meta stack_trace usage pedantic] - shared_preferences 0.5.10 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web] - sprintf 4.1.0 - strings 0.1.2 [unicode] - time 1.3.0 - url_launcher 5.5.0 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos] - uuid 2.2.0 [crypto convert] - validators 2.0.1 [vin_decoder] dev dependencies: - build_runner 1.10.1 [analyzer args async build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style glob graphs http_multi_server io js logging meta mime path pedantic pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml] - built_value_generator 7.1.0 [analyzer build build_config built_collection built_value source_gen quiver] - intl_translation 0.17.10 [analyzer args dart_style intl path petitparser] transitive dependencies: - _fe_analyzer_shared 6.0.0 [meta] - analyzer 0.39.14 [_fe_analyzer_shared args charcode cli_util collection convert crypto glob html meta package_config path pub_semver source_span watcher yaml] - archive 2.0.13 [crypto args path] - args 1.6.0 - asn1lib 0.6.5 - async 2.4.2 [collection] - basic_utils 2.6.2 [http logging json_annotation pointycastle asn1lib convert crypto] - build 1.3.0 [analyzer async convert crypto logging meta path glob] - build_config 0.4.2 [checked_yaml json_annotation meta path pubspec_parse yaml] - build_daemon 2.1.4 [built_collection built_value http_multi_server logging pedantic path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 1.3.11 [analyzer build crypto graphs logging path package_config pub_semver] - build_runner_core 6.0.1 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pedantic pool timing watcher yaml] - characters 1.0.0 - charcode 1.1.3 - charts_common 0.9.0 [collection intl logging meta vector_math] - checked_yaml 1.0.2 [json_annotation source_span yaml] - cli_util 0.1.4 [path] - clock 1.0.1 [meta] - cloud_firestore_platform_interface 2.0.1 [flutter meta collection firebase_core plugin_platform_interface] - cloud_firestore_web 0.2.0+1 [flutter flutter_web_plugins firebase http_parser meta firebase_core cloud_firestore_platform_interface js] - code_builder 3.4.1 [built_collection built_value collection matcher meta] - collection 1.14.13 - convert 2.1.1 [charcode typed_data] - csslib 0.16.2 [source_span] - dart_style 1.3.6 [analyzer args path source_span] - device_info_platform_interface 1.0.0 [flutter meta plugin_platform_interface] - file 5.2.1 [intl meta path] - firebase 7.3.0 [http http_parser js] - firebase_auth_platform_interface 2.0.1 [flutter meta firebase_core plugin_platform_interface] - firebase_auth_web 0.3.0+1 [flutter flutter_web_plugins firebase meta http_parser intl firebase_core firebase_auth_platform_interface js] - firebase_core_platform_interface 2.0.0 [flutter meta plugin_platform_interface quiver] - firebase_core_web 0.2.0 [firebase firebase_core_platform_interface flutter flutter_web_plugins meta js] - fixnum 0.10.11 - flutter_cache_manager 1.4.1 [flutter path_provider uuid http path sqflite pedantic clock file rxdart] - flutter_plugin_android_lifecycle 1.0.8 [flutter] - flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math] - glob 1.2.0 [async collection node_io path pedantic string_scanner] - graphs 0.2.0 - html 0.14.0+3 [csslib source_span] - http_multi_server 2.2.0 [async] - http_parser 3.1.4 [charcode collection source_span string_scanner typed_data] - image_picker_platform_interface 1.1.0 [flutter meta http plugin_platform_interface] - io 0.3.4 [charcode meta path string_scanner] - js 0.6.2 - json_annotation 3.0.1 - lists 0.1.6 - logging 0.11.4 - matcher 0.12.9 [stack_trace] - meta 1.1.8 - mime 0.9.7 - nested 0.0.4 [flutter] - node_interop 1.1.1 [js] - node_io 1.1.1 [node_interop path] - package_config 1.9.3 [path charcode] - path 1.7.0 - path_provider 1.6.14 [flutter path_provider_platform_interface path_provider_macos path_provider_linux] - path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter] - path_provider_macos 0.0.4+3 [flutter] - path_provider_platform_interface 1.0.3 [flutter meta platform plugin_platform_interface] - pedantic 1.9.0 - petitparser 3.0.4 [meta] - platform 2.2.1 - platform_detect 1.4.0 [meta pub_semver] - plugin_platform_interface 1.0.2 [meta] - pointycastle 1.0.2 - pool 1.4.0 [async stack_trace] - process 3.0.13 [file intl meta path platform] - pub_semver 1.4.4 [collection] - pubspec_parse 0.1.5 [checked_yaml json_annotation pub_semver yaml] - quiver 2.1.3 [matcher meta] - shared_preferences_linux 0.0.2+2 [file flutter meta path path_provider_linux shared_preferences_platform_interface] - shared_preferences_macos 0.0.1+10 [shared_preferences_platform_interface flutter] - shared_preferences_platform_interface 1.0.4 [meta flutter] - shared_preferences_web 0.1.2+7 [shared_preferences_platform_interface flutter flutter_web_plugins meta] - shelf 0.7.9 [async collection http_parser path stack_trace stream_channel] - shelf_web_socket 0.2.3 [shelf web_socket_channel stream_channel] - sky_engine 0.0.99 - source_gen 0.9.6 [analyzer async build dart_style glob meta path pedantic source_span] - source_span 1.7.0 [charcode collection meta path term_glyph] - sqflite 1.3.1 [flutter sqflite_common path] - sqflite_common 1.0.2+1 [synchronized path meta] - stack_trace 1.9.5 [path] - stream_channel 2.0.0 [async] - stream_transform 1.2.0 - string_scanner 1.0.5 [charcode meta source_span] - synchronized 2.2.0+2 - term_glyph 1.1.0 - timeago 2.0.27 - timing 0.1.1+2 [json_annotation] - typed_data 1.2.0 [collection] - unicode 0.2.4 [lists] - url_launcher_linux 0.0.1+1 [flutter] - url_launcher_macos 0.0.1+7 [flutter] - url_launcher_platform_interface 1.0.7 [flutter meta plugin_platform_interface] - url_launcher_web 0.1.2+1 [url_launcher_platform_interface platform_detect flutter flutter_web_plugins meta] - usage 3.4.2 [path] - vector_math 2.0.8 - vin_decoder 0.1.2 [meta basic_utils http random_string] - watcher 0.9.7+15 [async path pedantic] - web_socket_channel 1.1.0 [async crypto stream_channel] - xdg_directories 0.1.0 [path process flutter] - xml 4.2.0 [collection convert meta petitparser] - yaml 2.2.1 [charcode collection string_scanner source_span] ```

TahaTesser commented 4 years ago

Hi @larssn Can you please provide your flutter run --verbose and a complete reproducible minimal runnable code sample Thank you

google-oss-bot commented 4 years ago

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

larssn commented 4 years ago

I've updated the OP with runnable code, but that code snippet works. So I can't reproduce it. 😞