Skip to content

Background Functions onCreate first argument (snap) contains empty object when Firestore document added to collection #571

@gagamil

Description

@gagamil

[READ] Step 1: Are you in the right place?

  • For issues or feature requests related to the code in this repository
    file a Github issue.
    • If this is a feature request make sure the issue title starts with "FR:".
  • For general technical questions, post a question on StackOverflow
    with the firebase tag.
  • For general Firebase discussion, use the firebase-talk
    google group.
  • For help troubleshooting your application that does not fall under one
    of the above categories, reach out to the personalized
    Firebase support channel.

[REQUIRED] Step 2: Describe your environment

  • Operating System version: MacOS Mojave 10.14.4
  • Firebase SDK version:
    Python:
    firebase-admin==3.1.0; google-api-core==1.14.3; google-api-python-client==1.7.11; google-cloud-core==1.0.3; google-cloud-firestore==1.5.0
    Node:
    "firebase-admin": "^8.0.0"; "firebase-functions": "^3.1.0"
  • Library version: _____
  • Firebase Product: Firestore; Functions

[REQUIRED] Step 3: Describe the problem

When using Python Firestore client to add (not set document with id) document to a collection the respective Firestore background functions snap has empty object instead of the data. However the snap.id is correct.

Steps to reproduce:

  • Init Python Firestore Client.
  • Add document with data to a collection
  • Write and deploy a Firestore function (onCreate)
  • Check functions logs and see that snap.data() === {}

Relevant Code:

shell: export GOOGLE_APPLICATION_CREDENTIALS='<PATH_TO_JSON_FILE>'

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

Functions index.js:
const functions = require("firebase-functions");

exports.onNewMessage = functions.firestore
.document("messages/{messageId}")
.onCreate((snap, context) => {
console.log("Data: ", snap.data());

Now check Functions logs:

Data: {}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions