I’m getting auto generated IDs in my firestore collection even though I’m specifying IDs when creating documents.
I am currently load testing my FastAPI app, currently testing it synchronously. My firestore IDs are coming from a counter stored in firebase’s realtime DB. The counter consists of alphanumeric characters and I’m incrementing them in a transaction. I’m then seeing if a document with that ID exists in firestore, when I find a ID that doesn’t exist I use .set() to create a document with that ID.
def increment_realtimedb() -> str:
try:
return rdb.transaction(crement)
except db.TransactionAbortedError:
increment_realtimedb()
def insert_firestore(payload: dict):
new_id = increment_realtimedb()
doc = collection.document(new_id).get()
while doc.exists:
new_id = increment_realtimedb()
doc = collection.document(new_id).get()
collection.document(new_id).set(payload)
CodePudding user response:
Figured out that increment_realtimedb() was returning None somehow. I changed the while loop to check if new_id was None. That seems to have fixed the problem.
while doc.exists or new_id is None:
Edit: After further research it turns out realtime db will return None when you max out the retries for a transaction.
