Interaction with Firebase Firestore

Hi,
I’m writing an app that interacts with a Firebase/Firestore database - as an example, I’ve built a simple book list on Firestore and have the app reading data from the store (a pain because Firestore has a very weird [but probably essential] way of storing JSON data) and have managed to get the app to post new books to the Firestore db. So far so good, but I’m having problems making the data_grid refresh when a new book is added. I’ve checked your pages on data_grids but nothing seems to work. I suspect that the Anvil app is too quick to retrieve that data from Firestore, so the content has not been established in Firestore yet. Have you any ideas?
You can see the app at https://anvil.works/build#clone:PGM6EKAMNPS2ZKAX=KSGPHNR4ZWD3LTZQRQU5AIRK
The firestore DB is not protected with authentication yet (decided to finish it before I do that, since authentication adds yet another layer of awkwardness).
Many thanks
Alistair

1 Like

Hello,

A couple things I noticed with a cursory look:

Your get_book_list function was trying to return a variable called list. You should try to avoid giving variables the same name as Python’s built-in words. You can see that they show up in blue in the code editor and so that is an indication that they are special words. You could just call it “book_list” instead for example.

The refresh function was not actually being called. Rather than using a custom event to trigger that function, you could just call it directly (e.g., self.refresh_books()).

Does this help?

2 Likes

Yes - that worked - odd I didn’t think of it. Many thanks
Also - I’ve taken on board your other comment - changed list to book_list. Thanks
Alistair

1 Like