0

I am using Firebase's CloudFirestore feature for updating the entries in my database. When I run the code it works fine for around 10 seconds, then it crashes with the following error:

  File "C:\Users\mypc\AppData\Local\Programs\Python\Python35-32\lib\site-packages\google\api_core\grpc_helpers.py", line 78, in next
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.DeadlineExceeded: 504 Deadline Exceeded

Here is my implementation that causes the issue:

existing = db.collection(u'pages').where(u'season', u'==', u'summer').get()

for x in existing:
    obj = x.to_dict()
    doc_ref = db.collection(u'pages').document(u'%s' % (obj['uid'],))
    doc_ref.update({u'year': "2019"})  

As you can see it's a quite simple function and I have no idea why it crashes if it's working for the first 10 seconds. I am on a paid plan so exceeding the limit can't be the problem. My idea is that I am doing something very wrong and my code causes the error, or it's simply a bug.

halfer
  • 19,824
  • 17
  • 99
  • 186
rihekopo
  • 3,241
  • 4
  • 34
  • 63
  • 1
    About how many documents do you think you're changing? It seems like you might be running up against one of the limits in Cloud Firestore (https://firebase.google.com/docs/firestore/quotas) – Todd Kerpelman Apr 24 '19 at 16:20
  • @ToddKerpelman around 8000 - but I can't discover any pattern, sometimes it crashes after 50 documents, sometimes after 150. – rihekopo Apr 24 '19 at 16:46
  • Are you updating a same document, more than once, faster than once a second? Or each document get one single write? In the first case, could be an error caused by too much contention on your documents. – MichelDelpech Apr 24 '19 at 19:42
  • @Firebaser second case, a loop through the array and update each document once. – rihekopo Apr 25 '19 at 16:15
  • Possible duplicate of [Why aren't all my documents updated in Firestore?](https://stackoverflow.com/questions/52360438/why-arent-all-my-documents-updated-in-firestore) – Juan Lara Apr 30 '19 at 00:53
  • Fetch your doc references first and then iterate. The `get()` call has about a 20 second time out, see [#52360438](https://stackoverflow.com/questions/52360438/why-arent-all-my-documents-updated-in-firestore/52414780#52414780) – Juan Lara Apr 30 '19 at 00:59

0 Answers0