Issue with serverTimeStamp added to every updateDoc() call

Continuing the discussion from Unofficial Anvil Firebase Integration v0.1🔥:

There is a particular instance where I update an array of maps key in my document, and I receive the following error:

ExternalError: FirebaseError: [code=invalid-argument]: Function updateDoc() called with invalid data. serverTimestamp() is not currently supported inside arrays

It seems to only happen with certain users, so I think it is a device specific issue, but it has to do with the serverTimeStamp appended to every updateDoc() call in the firebase_client() library.

Has anyone else had this issue?

Thanks!

I think I resolved it by making the call directly from js (circumventing the library):

anvil.js.call('updateDoc',fs.proxy_fs,doc_ref,fs.utility.to_proxy(update))

Hi @anthonys,

never had this issue but a quick search on the web shows that this is a limitation of firestore itself.
So you workaround will most likely not prevent the bug from happening:

It seems as if you should store it in a dictionary if possible.

I figured out my issue…somewhat.

I am not adding any serverTimeStamps to my array, but when I use get_doc and that uses from_proxy, that somehow is adding a update_timestamp to every dictionary in my array, maybe because I have a timestamp key in those dictionaries.

I then try to save by appending to that array and calling update_doc with that new array which contains the serverTimeStamps added to my dictionaries by from_proxy

Example:

Here is what I am saving:

drop_off_photo = {
      'name':name,
      'timestamp':time_stamp,
      'url':url,
      'ref':ref_string,
      'private':True,
      'type':"Drop Off Photo",
      'uploader':{
        'user':f"{globals.rolemanager.user['name']}",
        'id':globals.rolemanager.id, 
      },
    }

Here is what is returned when calling get_doc

{
'name': 'OpenTrailer_401.png', 
'timestamp': '2023-10-02T09:55:16.608000-07:00',
 'url': 'dummy url',
 'ref': 'drop_off_photos/OpenTrailer_401.png', 
'private': True,
 'type': 'Drop Off Photo', 
'uploader': {'user': 'dummy name', 'id': 'dummy_id'}, 
'order': {'order number': 1111, 'uid': 'dumm_uid'}, 
'update_timestamp': <__PRIVATE_ServerTimestampFieldValueImpl proxyobject>}, 

And this is every dictionary within an array