Skip to content

functions.database.DeltaSnapshot#key outputs incorrect value #36

@cevanish12

Description

@cevanish12

Version info

firebase-functions: ^0.5

firebase-admin: ^4.1.4

Test case

This is similar to what I have:

const functions = require('firebase-functions');

exports.myFunction = functions.database.ref('/Accounts/{uId}/{accountId}/')
    .onWrite(event => {
	 event.data.current.forEach(function(item) {
	     console.log(item.key);
	 });
    });

Were you able to successfully deploy your functions?

Yup. I'd classify this as more of a semantic error.

Expected behavior

If my path was /Accounts/1234/5678, the key should give me 5678.

Actual behavior

The key property gives me 12345678 (combining the second and third level children).

Temporary fix

I put this on top of my index.js file, and it seems to fix the problem, though it might not cover all cases.

const functions = require('firebase-functions');

functions.database.DeltaSnapshot.prototype._fullPath = function () {
    var out = (this._path || '') + '/' + (this._childPath || '');
    if (out === '') {
        out = '/';
    }
    return out;
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions