2

I want to update my firestore database by creating an ArrayUnion Object. Unfortunately my update method produces the following error:

 TypeError: ('Cannot convert to a Firestore Value', <google.cloud.firestore_v1beta1.transforms.ArrayUnion object at 0x04CDEF90>,
'Invalid type', <class 'google.cloud.firestore_v1beta1.transforms.ArrayUnion'>)

My approach is based on the official docs https://github.com/googleapis/google-cloud-python/blob/master/firestore/google/cloud/firestore_v1beta1/_helpers.py

This implementation worked for me in the past, but for a couple of days i cant get it to succeed.

import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
from firebase_admin import db    
from google.cloud.firestore_v1beta1 import ArrayUnion, ArrayRemove

class TwitFire:

    def __init__(self):
       # Use a service account
       cred = credentials.Certificate('./credentials')
       firebase_admin.initialize_app(cred)
       self.client = firestore.client()

    def getRef(self, collectionName, documentName):
        return self.client.collection(collectionName).document(documentName)

    def set(self, ref, entry):
        return ref.set(entry)

    def update(self, ref, entry):
        return ref.update(entry)

    def updateTweets(self, ref, entry):
        return ref.update({u'retweets': ArrayUnion([entry])})

    def create(self, ref, entry):
        return ref.create(entry)
2
  • 1
    Just wanted to confirm that i was indeed using google-cloud-firestore==0.32.1 Commented Apr 17, 2019 at 8:33
  • Apparently the right import should be from google.cloud.firestore_v1 import ArrayUnion see Commented Apr 18, 2019 at 19:49

1 Answer 1

1

Are you using google-cloud-firestore==0.32.1?

Experienced the same issue when I upgraded to 32.1.

Downgraded to google-cloud-firestore==0.31.0 and the issue is gone. Maybe a bug in the recent version.

Note that I did not tested locally, just changed the requirements.txt

EDIT:

from google.cloud.firestore_v1beta1 import ArrayUnion

should be used with 0.31.0 when using 0.32.0 and above the import must be:

from google.cloud.firestore_v1 import ArrayUnion

See this

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.