FlutterFlow / flutterflow-issues

A community issue tracker for FlutterFlow.
129 stars 26 forks source link

Firebase read document throws DartError: TypeError: null: type 'Null' is not a subtype of type 'Map<String, dynamic>' when reference doesn't exist #3961

Open kristoflievens opened 1 month ago

kristoflievens commented 1 month ago

Can we access your project?

Current Behavior

When performing a Firebase read document backend call in an Action flow for a document reference that no longer exists the following excpetion is thrown: DartError: TypeError: null: type 'Null' is not a subtype of type 'Map<String, dynamic>' when reference doesn't exist

The Action flow stops further processing and doesn't allow to handle this error further down the flow.

Expected Behavior

The Firebase read document backend call Action should return null via the Ouput Variable instead of crashing

Steps to Reproduce

  1. Create a new blank Flutterflow project and enable Web. Create a new Firebase project in eur3 (don't enable authentication/create user collection; don't select an initial page) in the project creation wizard.
  2. From Flutterflow generate the config files for Firebase
  3. From Flutterflow, create 2 collections in firebase A and B from scratch. Add a field Title of type string to both collections. Add a field reftoB of type Document reference to collection B to collection A.
  4. Under firestore settings in Flutterflow, change the firestore rules so everyone can do everything and deploy the rules
  5. From Flutterflow Enable Auth on Firebase -> enable Email/Password
  6. From Flutterflow create one record on collection B
  7. From flutterflow create one record in collection A with a 'reftoB' field referencing the record created in step 6
  8. Delete all records in collection B
  9. To the home page in FlutterFlow add 2 buttons called "query" and "read"
  10. On the 'query' button, add an 'on tap' action 'Firestore Query' that queries the firestore collection A and returns a single doucment in the Action Outpout variable 'outputVariableA'
  11. On the 'read' button, add an 'on tap' action 'read document' that reads the document references in field 'reftoB' in the Action Outpout variable 'outputVariableA' from the 'query' button and set the Action Output variable m= 'outputVariableB'
  12. Open the Action Flow Editor for the 'read' button and add an action 'Information Dialog' Alert Dialog after the action created in step 11. In the message field of the Alert Dialog, select the title from the 'outputVariableB' of the Action Outputs
  13. Run the app in Test mode. Open the Developer tools of your browser when the app is running (by pressing F12 for a Chromium browser).
  14. push the 'query' button to retrieve the one record from collection A
  15. Push the 'read' button to retrieve the record from collection B that has been deleted in step 8.
  16. The alert dialog configured in step 12 will not be displayed, instead you will see the following error in the Console of the Developer Tools in your browser: Uncaught (in promise) DartError: TypeError: null: type 'Null' is not a subtype of type 'Map<String, dynamic>' at Object.throw_ [as throw] (dart_sdk.js:11994:11) at Object._failedAsCheck (dart_sdk.js:22922:15) at dart_rti.Rti.new._generalAsCheckImplementation (dart_sdk.js:22908:14) at BRecord.fromSnapshot (b_record.dart:39:42) at b_record.dart:35:37 at _RootZone.runUnary (dart_sdk.js:46938:59) at _FutureListener.then.handleValue (dart_sdk.js:42334:29) at handleValueCallback (dart_sdk.js:42938:49) at _Future._propagateToListeners (dart_sdk.js:42976:17) at [_completeWithValue] (dart_sdk.js:42817:23) at async._AsyncCallbackEntry.new.callback (dart_sdk.js:42851:35) at Object._microtaskLoop (dart_sdk.js:47394:13) at _startMicrotaskLoop (dart_sdk.js:47400:13) at dart_sdk.js:43200:9

Reproducible from Blank

Bug Report Code (Required)

IT4wl8nfsM9NsdtJ7ZPud8dFmioRMjs7ROYe0+t9aCs9f5ToPJYQe8/6P0xoQtfkdFZAPmGmp14epMLSidrIUOwqGEicUaZJwqgJUwr/TnqiacyTF7qwdUd6JJpTf0i75p+rvSJDJrNaZUYf12CmPt+yZHPDQ5iyPno8Sq/LZO4=

Visual documentation

image

Environment

- FlutterFlow version: 5.0.2+
- Platform:Web
- Browser name and version:Edge Version 129.0.2792.65 (Version officielle) (64 bits)
- Operating system and version affected: Windows 11

Additional Information

This bug makes it impossible to properly handle errors related to references between documents in different collections that have been deleted.

Alezanello commented 1 month ago

Hello!

I haven’t tested this myself yet, but I’ve reviewed the project you provided. Have you tried setting a conditional to check if the ID is set before attempting to read the document? Additionally, after triggering the alert dialog, did you verify if the document exists?

image.png
kristoflievens commented 1 month ago

Hi @Alezanello,

The ID exists, but that's not really the point, because the ID is pointing to a non-existing document.

Additionally, after triggering the alert dialog, did you verify if the document exists? -> yes, but that code is never executed, so it is of no use

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 7 days with no activity. If there are no further updates, a team member will close the issue.

kristoflievens commented 1 month ago

Hi @Alezanello , do you need additional input on this issue? Are you able to reproduce it?

github-actions[bot] commented 3 weeks ago

This issue is stale because it has been open for 7 days with no activity. If there are no further updates, a team member will close the issue.

clintdoriot commented 3 weeks ago

I'm running into the same issue.