Skip to content

Firestore SERVER_TIMESTAMP only works with "set" and not "add" #6826

@Emsu

Description

@Emsu

Mac OSX Mojave 10.14
Python 3.7.0
google-cloud-firestore==0.30.0

Steps to reproduce

  1. Run the two code example below. set works but add doesn't. The expected behavior is that they both parse the firestore.SERVER_TIMESTAMP constant the same way.

Code example

this fails

rows = firestore.client().collection('rows')
rows.add(
                dict(
                    created_at=firestore.SERVER_TIMESTAMP,
                    updated_at=firestore.SERVER_TIMESTAMP))

this works

rows = firestore.client().collection('rows')
rows.document('test_id').set(
                dict(
                    created_at=firestore.SERVER_TIMESTAMP,
                    updated_at=firestore.SERVER_TIMESTAMP))

Seems like it was forgotten to add SERVER_TIMESTAMP parsing to the add method and it's only on the set method.

Stack trace

17:30:32 tables.1    |   File "app.py", line 1337, in mutate
17:30:32 tables.1    |     updated_at=firestore.SERVER_TIMESTAMP))
17:30:32 tables.1    |   File "env/lib/python3.7/site-packages/google/cloud/firestore_v1beta1/collection.py", line 160, in add
17:30:32 tables.1    |     fields=_helpers.encode_dict(document_data))
17:30:32 tables.1    |   File "env/lib/python3.7/site-packages/google/cloud/firestore_v1beta1/_helpers.py", line 536, in encode_dict
17:30:32 tables.1    |     for key, value in six.iteritems(values_dict)
17:30:32 tables.1    |   File "env/lib/python3.7/site-packages/google/cloud/firestore_v1beta1/_helpers.py", line 536, in <dictcomp>
17:30:32 tables.1    |     for key, value in six.iteritems(values_dict)
17:30:32 tables.1    |   File "env/lib/python3.7/site-packages/google/cloud/firestore_v1beta1/_helpers.py", line 520, in encode_value
17:30:32 tables.1    |     'Invalid type', type(value))
17:30:32 tables.1    | TypeError: ('Cannot convert to a Firestore Value', <object object at 0x104fdebe0>, 'Invalid type', <class 'object'>)

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the Firestore API.priority: p2Moderately-important priority. Fix may not be included in next release.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