firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

Cannot decode type from Firestore Value

Open ghost opened this issue 8 years ago • 19 comments

The Firestore hooks no longer work in my firebase project. When I try to retrieve data from the event using DeltaDocumentSnapshot.data(), I receive the following error message in the function logs:

Error: Cannot decode type from Firestore Value: {"stringValue":"world"}

Version info

firebase-functions: 0.7.4

firebase-tools: 3.16.0

firebase-admin: 5.5.1

Test case

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

exports.findSearchOnOffer = functions.firestore.document('offers/{offerId}').onCreate(event => {
  console.log(event);
  var offerData = event.data.data();
  return 0;
});

Steps to reproduce

  • copy and paste the above snippet into the functions/index.js
  • deploy to Firebase
  • create a new document in the offers collection to trigger the cloud function

Were you able to successfully deploy your functions?

Functions deployed successfully, no errors.

Expected behavior

It should be possible to access object data as shown in the docs

Actual behavior

Error: Cannot decode type from Firestore Value: {"stringValue":"world"}
     at DocumentSnapshot._decodeValue (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:464:15)
     at DocumentSnapshot.data (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:322:26)
     at exports.findSearchOnOffer.functions.firestore.document.onCreate.event (/user_code/index.js:13:30)
     at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:59:27)     at next (native)
     at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
     at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
     at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:53:36)
     at /var/tmp/worker/worker.js:695:26
     at process._tickDomainCallback (internal/process/next_tick.js:135:7)

Here is the console output of the event:

DocumentSnapshot {   _ref:     DocumentReference {      _firestore:        Firestore {         makeAuthenticatedRequest: [Object],
        authClient: [Object],
        baseUrl: undefined,
        getCredentials: [Function: bound getCredentials],
        globalInterceptors: [],
        interceptors: [Object],
        packageJson: [Object],
        projectId: '[...]',
        projectIdRequired: true,
        Promise: [Function: Promise],
        grpcMetadata: [Object],
        maxRetries: undefined,
        userAgent: 'gcloud-node-firestore/0.8.2',
        activeServiceMap_: Map {},
        protos: {},
        _preferTransactions: true,
        _lastSuccessfulRequest: null,
        api: [Object],
        _referencePath: [Object] },
     _referencePath: 
      ResourcePath {
        segments: [Object],
        _formattedName: undefined,
        _projectId: '[...]',
        _databaseId: '(default)' } },
  _fieldsProto: { hello: { stringValue: 'world' } },
  _readTime: undefined,
  _createTime: '2017-12-19T14:01:50.144095000Z',
  _updateTime: '2017-12-19T14:01:50.144095000Z' }

It looks like the problem is with this line _fieldsProto: { hello: { stringValue: 'world' } }.

ghost avatar Dec 19 '17 13:12 ghost

Similar problem: https://stackoverflow.com/questions/47886043/cannot-decode-type-from-firestore-value

puf avatar Dec 19 '17 14:12 puf

i'm in similar problem too

DuanTranHuy avatar Dec 19 '17 16:12 DuanTranHuy

I also have that problem.

rubenCortes avatar Dec 19 '17 17:12 rubenCortes

I am having the same issue with firestore and cloud functions it was working perfectly yesterday.

mikekaranja avatar Dec 19 '17 18:12 mikekaranja

Same problem, didn't change the code and it's giving me this error over and over. Wasted so much time trying to debug this.

maddada avatar Dec 19 '17 18:12 maddada

me too, I've been trying to fix it for several hours

rubenCortes avatar Dec 19 '17 18:12 rubenCortes

Hi all, could you try pinning your firebase-functions version to 0.7.3 (the previous release) and redeploy your functions to see if that resolves the issue?

justinrosenthal avatar Dec 19 '17 19:12 justinrosenthal

To help us debug, could anyone who is experiencing this error please post the contents of your package.json?

justinrosenthal avatar Dec 19 '17 20:12 justinrosenthal

This is supposed to be fixed with SDK version 0.7.5.

CodingDoug avatar Dec 20 '17 01:12 CodingDoug

Yep, the just-released version 0.7.5 of firebase-functions should resolve this error. Please update to the latest version and redeploy your functions to get the fix.

justinrosenthal avatar Dec 20 '17 01:12 justinrosenthal

It works, thanks.

rubenCortes avatar Dec 20 '17 05:12 rubenCortes

It's happening again on v0.8.1

andoshin11 avatar Jan 22 '18 14:01 andoshin11

@andoshin11 Can you check your package.json to see what firebase-admin version you have? It should be 5.8.1

laurenzlong avatar Jan 22 '18 18:01 laurenzlong

Happening with 0.8.2

Edit verifying with the latest firebase-admin version per @laurenzlong comment. Update works with "firebase-admin": "^5.11.0" and "firebase-functions": "^0.8.2"

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase serve --only functions",
    "shell": "firebase experimental:functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "firebase-admin": "~5.4.2",
    "firebase-functions": "^0.8.2"
  },
  "private": true
}
$ npm ls firebase-functions
functions@ /Users/ralphs/Workspace/divvy/functions
└── [email protected]

r4lphio avatar Mar 15 '18 23:03 r4lphio

"firebase-admin": "~5.12.0",
"firebase-functions": "^1.0.1"

still notworking... here is my log, cannot use snap.data();

{"_ref":{"_firestore":{"grpcMetadata":{"_internal_repr":{"x-goog-api-client":["gl-node/6.11.5 gccl/0.13.1 grpc/1.10.1"]}},"userAgent":"gcloud-node-firestore/0.13.1","activeServiceMap_":{},"protos":{},"_preferTransactions":true,"_lastSuccessfulRequest":null,"api":{"Firestore":{"auth":{"authClientPromise":{},"authClient":null,"googleAuthClient":{"jsonContent":null,"cachedCredential":null,"_cachedProjectId":null},"config":{"scopes":["https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/datastore"],"projectId":"cat-properties","libName":"gccl","libVersion":"0.13.1"},"credentials":null,"environment":{},"jwtClient":null,"projectId":"cat-properties","token":null}}},"_referencePath":{"segments":[],"_projectId":"cat-properties","_databaseId":"(default)"}},"_referencePath":{"segments":["posts","2JeMu5VFWC3QOZ3fueHU"],"_projectId":"cat-properties","_databaseId":"(default)"}},"_fieldsProto":{"message":{"valueType":"stringValue","stringValue":"textislowercase666"}},"_createTime":"2018-04-09T08:10:19.591199000Z","_updateTime":"2018-04-09T08:10:19.591199000Z"}

sattha avatar Apr 09 '18 08:04 sattha

@sattha Are you referring to a deployed function or a local emulated function?

laurenzlong avatar Apr 09 '18 21:04 laurenzlong

I was unable to reproduce this bug using: firebase-functions v1.0.1 firebase-admin v5.12.0

I deployed this function:

exports.fsAction = functions.firestore.document('input/{id}').onCreate(snap => {
    console.log(snap.data())
      return snap.ref.set({bar: 'faz'});
  }),

snap.data() printed out "{hello: world}" as expected.

If you are seeing errors when emulating, that is a different bug, please open a new one.

laurenzlong avatar Apr 10 '18 21:04 laurenzlong

Thanks @laurenzlong ! Those versions work. Haven't been able to get any other versions to work, anyone coming here use: firebase-functions v1.0.1 firebase-admin v5.12.0

3210jr avatar May 29 '18 14:05 3210jr

The latest versions of both of these modules should also work: firebase-functions v1.0.3 firebase-admin v5.12.1

Please let me know if they don't

laurenzlong avatar May 30 '18 00:05 laurenzlong