Skip to content

Firestore: ArrayUnion not working in latest version #7720

@GuanacoDevs

Description

@GuanacoDevs

Environment details

  1. google-cloud-firestore==0.32.1
  2. google-cloud-function

Steps to reproduce

  1. When using ArrayUnion with google-cloud-firestore==0.32.1, the function crashes with the following message:

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

Code example

Virtually the same code from the snippets

from google.cloud.firestore_v1beta1 import ArrayUnion
events_ref.update({'events': ArrayUnion([event_id])})

Stack trace

Traceback (most recent call last):
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 383, in run_background_function
    _function_handler.invoke_user_function(event_object)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 217, in invoke_user_function
    return call_user_function(request_or_event)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 214, in call_user_function
    event_context.Context(**request_or_event.context))
  File "/user_code/main.py", line 62, in user_delete_anonymous
    if check_event(context.event_id):
  File "/user_code/main.py", line 27, in check_event
    events_ref.update({'events': ArrayUnion([event_id])})
  File "/env/local/lib/python3.7/site-packages/google/cloud/firestore_v1/document.py", line 379, in update
    batch.update(self, field_updates, option=option)
  File "/env/local/lib/python3.7/site-packages/google/cloud/firestore_v1/batch.py", line 112, in update
    reference._document_path, field_updates, option
  File "/env/local/lib/python3.7/site-packages/google/cloud/firestore_v1/_helpers.py", line 822, in pbs_for_update
    update_pb = extractor.get_update_pb(document_path)
  File "/env/local/lib/python3.7/site-packages/google/cloud/firestore_v1/_helpers.py", line 459, in get_update_pb
    name=document_path, fields=encode_dict(self.set_fields)
  File "/env/local/lib/python3.7/site-packages/google/cloud/firestore_v1/_helpers.py", line 215, in encode_dict
    return {key: encode_value(value) for key, value in six.iteritems(values_dict)}
  File "/env/local/lib/python3.7/site-packages/google/cloud/firestore_v1/_helpers.py", line 215, in <dictcomp>
    return {key: encode_value(value) for key, value in six.iteritems(values_dict)}
  File "/env/local/lib/python3.7/site-packages/google/cloud/firestore_v1/_helpers.py", line 200, in encode_value
    "Cannot convert to a Firestore Value", value, "Invalid type", type(value)
TypeError: ('Cannot convert to a Firestore Value', <google.cloud.firestore_v1beta1.transforms.ArrayUnion object at 0x2a79c19b2fd0>, 'Invalid type', <class 'google.cloud.firestore_v1beta1.transforms.ArrayUnion'>)

Changing to google-cloud-firestore==0.31.0 in my requirements.txt fixes the issue, tested 0.32.0 with the same crash.

Best Regards

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions