Skip to content

Firestore: using ArrayUnion in 'update()' or 'set(merge=true)' on nested data removes all previous data #14

@A-Iskakov

Description

@A-Iskakov

Environment details

  1. Cloud Firestore
  2. Ubuntu 18.04
  3. Python 3.7
  4. google-cloud-firestore Version: 0.31.0

Steps to reproduce

  1. Use ArrayUnion([1,2,3]) on updating nested data in Document reference (see code example bellow)

Code example

from google.cloud import firestore
from google.cloud.firestore_v1beta1 import ArrayUnion

# creating reference
db = firestore.Client()
doc_ref = db.collection(u'test_collection').document(u'test_document')

# creating initial data with nested tree_1
doc_ref.set(
            {
                u'forest': {
                    u'tree_1': u'oak'
                }
            }
        )

# getting document after initial data
print('Here is initial data with 1 nested tree', doc_ref.get().to_dict())

# adding tree_2 to nested data (tree_1 remains in nested data)
doc_ref.set(
            {
                u'forest': {
                    u'tree_2': u'pine'
                }
            },
            merge=True
        )

print('Here is 2 trees in nested data after using set(merge=true)', doc_ref.get().to_dict())

# this code removes other nested data in document
# including tree_1 and tree_2, even if merge=true  is used
doc_ref.set(
            {
                u'forest': {
                    u'tree_3': ArrayUnion([u'spruce'])
                }
            },
            merge=True
        )

print('after using ArrayUnion, all previous nested data is removed', doc_ref.get().to_dict())

Stack trace

Here is initial data with 1 nested tree {'forest': {'tree_1': 'oak'}}
Here is 1 initial tree and 1 additional tree after set(merge=true) {'forest': {'tree_1': 'oak', 'tree_2': 'pine'}}
after using set(merge=true) with ArrayUnion all nested data is removed {'forest': {'tree_3': ['spruce']}}

Many Thanks!

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.api: firestoreIssues related to the googleapis/python-firestore API.priority: p2Moderately-important priority. Fix may not be included in next release.status: blockedResolving the issue is dependent on other work.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions