Skip to content

Firestore: Incorrect implementation of collection.add() #9629

@samtstern

Description

@samtstern

Environment details

Platforms: all

$ python --version Python 2.7.17rc1 
$ pip show google-cloud-firestore Name: google-cloud-firestore Version: 1.5.0 Summary: Google Cloud Firestore API client library Home-page: https://github.com/GoogleCloudPlatform/google-cloud-python Author: Google LLC Author-email: googleapis-packages@google.com License: Apache 2.0 Location: /usr/local/google/home/samstern/.local/lib/python2.7/site-packages Requires: google-api-core, google-cloud-core, pytz Required-by: firebase-admin 

Steps to reproduce

This was originally reported to me here, and I reproduced it:
firebase/firebase-functions#574

Python code:

import firebase_admin from firebase_admin import credentials firebase_admin.initialize_app() from google.cloud import firestore db = firestore.Client() print 'Adding' db.collection('messages').add({'message':'Hello from Python'}) print 'Added'

Cloud Functions:

const functions = require("firebase-functions"); exports.onNewMessageLength = functions.firestore .document("messages/{messageId}") .onCreate((snap, context) => { console.log("onCreate Data: ", JSON.stringify(snap.data())); return 0; }); exports.onUpdatedMessageLength = functions.firestore .document("messages/{messageId}") .onUpdate((change, context) => { console.log("onUpdate Data: ", JSON.stringify(change.after.data())); return 0; });

Running this in the Firebase emulators I see:

$ firebase emulators:exec "GCLOUD_PROJECT='fir-dumpster' python py/main.py && sleep 5" ⚠ Your requested "node" version "8" doesn't match your global version "10" ✔ functions: Emulator started at http://localhost:5001 i firestore: Serving ALL traffic (including WebChannel) on http://localhost:8080 ⚠ firestore: Support for WebChannel on a separate port (8081) is DEPRECATED and will go away soon. Please use port above instead. i firestore: Emulator logging to firestore-debug.log ✔ firestore: Emulator started at http://localhost:8080 i firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080 i functions: Watching "/tmp/tmp.OWPbChnnJ2/functions" for Cloud Functions... ✔ functions[onNewMessageLength]: firestore function initialized. ✔ functions[onUpdatedMessageLength]: firestore function initialized. i Running script: GCLOUD_PROJECT='fir-dumpster' python py/main.py && sleep 5 /usr/local/google/home/samstern/.local/lib/python2.7/site-packages/google/auth/_default.py:66: UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/. warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING) Adding Added i functions: Beginning execution of "onNewMessageLength" > onCreate Data: {} i functions: Finished "onNewMessageLength" in ~1s i functions: Beginning execution of "onUpdatedMessageLength" > onUpdate Data: {"message":{"type":"Buffer","data":[72,101,108,108,111,32,102,114,111,109,32,80,121,116,104,111,110]}} i functions: Finished "onUpdatedMessageLength" in ~1s ✔ Script exited successfully (code 0) i Shutting down emulators. i Stopping functions emulator i Stopping firestore emulator 

What I should see is only the onCreate function firing and it should have the full data. The implementation here is not correct:
https://github.com/googleapis/google-cloud-python/blob/master/firestore/google/cloud/firestore_v1/collection.py#L159-L180

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