Skip to content

Functions emulator triggers on delete of document that does not exist #2978

Description

@wooliet

[REQUIRED] Environment info

firebase-tools: 9.1.0

Platform: macOS

[REQUIRED] Test case

A. Cloud function set to trigger on document "write" events:

exports.onDocWrite = functions.firestore.document(
  '/test-collection/{id}'
).onWrite(change => {
  const orig = change.before.data();
  console.log(orig);
  return true;
});

B. Code that deletes a document to trigger onDocWrite

async function main () {
  const ref = admin.firestore().doc(
    '/test-collection/QdfGrVXTYqPqIOxuXpbp'
  );
  await ref.delete();
  process.exit(0);
}

[REQUIRED] Steps to reproduce

  1. Create the onDocWrite firestore cloud function and deploy to production environment
  2. Manually add a new document to test-collection
  3. Run code to delete the document and observe logged output
  4. Run code to delete the document again: no logged output
  5. Repeat the above steps against the emulated environment

[REQUIRED] Expected behavior

Emulated environment should produce no logged output when deleting a document that does not exist.

[REQUIRED] Actual behavior

Cloud function in emulated environment is triggered on delete of the document that does not exist. It logs "undefined" for the document's before.data().

i  functions: Beginning execution of "onDocWrite"
i  functions: Finished "onDocWrite" in ~1s
>  undefined

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions