Cloud firestore: get() always timesout in a python create trigger

I have a straightforward Cloud Firestore "on-create" trigger that needs to query another collection. But, the get() for a document within that collection always times out. The collection being queried is empty and the only thing in the logs is a "timeout".

This works outside by itself.

Maybe it has something to do with the way the "db" client is being initialized?


import firebase_admin
from firebase_admin import firestore

firebase_admin.initialize_app()

def on_insert(data, context):
    print("fields:", data["value"]["fields"])
    workgroup_id, namespace_id = None, None
    try:
        workgroup_id = data["value"]["fields"]["workgroup_id"]["stringValue"]
        namespace_id = data["value"]["fields"]["namespace_id"]["stringValue"]
    except KeyError:
        print("!!Ignoring trigger with unexpected workgroup_id/namespace_id values")
        return
    print (f"workgroup_id: {workgroup_id}, namespace_id: {namespace_id}")
    db = firestore.client()
    print("getting ref")
    ref = db.collection(u"ExtendedAttributesCounter").document(workgroup_id)
    print("before get()")
    # gets stuck here
    doc = ref.get()
    print("exists", doc.exists)

1 answer

  • answered 2021-04-08 21:46 user1987833

    The issue turned out to be that the service account @appspot.gserviceaccount.com was disabled. Interestingly, a NodeJS trigger (with the same functionality) gave a more detailed error message that pointed to an authentication error. Python function logs just noted a timeout.