Bug while storing data in the TinyDB

While I was writing for help about the particular “Runtime Error - End application” error, I found a bug and I was able to identify the root cause.

So I had blocks like below, where I was fetching the data from Firebase and then storing it under TinyDB at login. I do not have values for User_VehicleNumber and User_isDriver. I found out that in the first tinydb store value User_vehicleNumber block, if the value is not found then it will store “not found” (as its a string), if the value is literally not there. However, in the second block User_isDriver, it is encountering the mentioned error(Runtime Error). Somehow tinyDB is not able to store boolean values, if the data does not exist hence throws an error.

I just wanted to write about this, maybe some other folks face the same error and this can be helpful for them. This might be possible for other component as well.

Issue: “Runtime error end application”
Cause: TinyDB not able to store the boolean value in case not found.
Fix: Either create the values before storing it under TinyDB or change the boolean to string format (“false” or “true”) instead of the boolean component.

Hi dear,

I believe the problem is very simple to fix.
Based on how you set up the blocks, if GetValueForKey(Vehicle) is not found, GetValueForKey(Number) will not search within a dictionary but instead within a text value.


The correct block setup is like this.

This way, if Vehicle is not found, it will return an empty dictionary, and getValueForKey(Number) will search within an empty dictionary instead of searching in a text value.

Same for User_isDriver

Actually I want some values to show up instead of just empty dictionary so I kept like “not found”. I’ll change it in future with real dummy data but not an empty one. However the main issue was with TinyDB not storing Boolean true or false in case data not found.

In fact, as I showed you, if Number is not found in Vehicle, the output is “not found”.

The same applies to the boolean value, Vehicle must be a dictionary, so its orIfNotFound must also be a dictionary.

1 Like

I see now, I’ll try that.