https://github.com/firebase/firebase-functions/issues/285
firebase-functions:
v2.2.0
I have upgraded from functions v2.1.0 to v2.2.0 and my triggers have started returning Date instead of Timestamp.
I would expect it to be another way around after breaking changes announced in v2.2.0.
export const markStats = functions.firestore
.document("/workBites/{markId}")
.onWrite((snap, context) => {
const previousData: DocumentData = snap.before.data() || {}
const newData: DocumentData = snap.after.data() || {}
const timestamp: Date = actionType.isDelete
? previousData.timestamp && previousData.timestamp.toDate() // <- this is not returning Timestamp anymore, but Date?
: newData.timestamp && newData.timestamp.toDate()
}
onWrite -> snap.before.data() should contain timestamp types as Timstamp
Log from v2.1.0:
3:07:26.913 PM
markStats
Function execution took 6929 ms, finished with status: 'ok'
3:07:19.986 PM
markStats
Function execution started
onWrite -> snap.before.data() contains timestamp types as Date
Log from v2.2.0:
Function execution took 7 ms, finished with status: 'error'
3:00:51.346 PM
markStats
TypeError: previousData.timestamp.toDate is not a function at processMarkData (/user_code/lib/listener/markStats.js:29:60) at exports.markStats.functions.firestore.document.onWrite (/user_code/lib/listener/markStats.js:20:12) at cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:105:23) at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:135:20) at /var/tmp/worker/worker.js:779:24 at process._tickDomainCallback (internal/process/next_tick.js:135:7)
3:00:51.343 PM
markStats
Function execution started
yes
Getting the same error:
TypeError: newData.created_at.toDate is not a function
Especially as this should have already been fixed within 2.0.2
It was fixed in 2.0.2, it is working well for me in 2.1.0,
but in 2.2.0 it seems that we have a regression of the same issue.
Same, noticed that all my .toDate() calls were breaking.
Its correctly saved as a Timestamp in firestore:

But being retuned as a ISO datestring in my cloud functions listener:

Downgrading back to 2.1.0 has fixed this issue for now.
Would like to hear whether 2.2.0 behaviour is a bug or if this is intended.
Hey all, I'm looking into this issue right now, thanks a ton for bringing it to our attention. In the last release, we upgraded our peer dependency to firebase-admin v7.0.0, which should have changed the default behavior of Firestore to {timestampsInSnapshots: true}. Because of this, we removed a few lines where fiurebase-functions was manually setting this:. I'm going to do some testing to see if that is what's causing this issue.
@joehan I noticed yesterday that I am using firebase-functions v2.2.0 with firebase-admin v6.5.1. This might be the reason for this? I will upgrade firebase-admin to v7.0.0 later today and see if it resolves the problem.
I am using functions 2.2.0 with admin ^6.4.0 and timestamp enforcement:
const firestore = admin.firestore()
firestore.settings({ timestampsInSnapshots: true })
I would expect that this setup still works or at least very clear message in the changelog that we should update to admin 7.0.0.
@dbacinski we updated the peer dependency in the 2.2.0 release to point to v7.0.0 of firebase-admin. You should have gotten a warning if using functions with a noncompatible peer dependency like 6.4.0. Can you try upgrading to 7.0.0 to see if that fixes the issue?
I have updated dependencies to:
"firebase-admin": "7.0.0",
"firebase-functions": "2.2.0",
"@google-cloud/firestore": "^1.0.0",
Now Timestamp is returned correctly :tada:.
But I am getting an error message:
The timestampsInSnapshots setting now defaults to true and you no
longer need to explicitly set it. In a future release, the setting
will be removed entirely and so it is recommended that you remove it
from your firestore.settings() call now.
Even thou firestore configuration is still in place:
const firestore = admin.firestore()
firestore.settings({ timestampsInSnapshots: true })
Seams that admin configuration is not respected by functions which seam to be a root cause of this issue.
@dbacinski I think that is just a warning saying that
firestore.settings({ timestampsInSnapshots: true })
is now redundant as it its the default
I was not getting this error message for functions 2.1.0, but only if admin.firestore().settings({ timestampsInSnapshots: true }) was set. Hard to tell if this is functions or admin issue from my perspective.
I will try to test it without firestore.settings({ timestampsInSnapshots: true })
Hi @dbacinski glad you got it working when you upgraded firebase-admin! Yes, @developcodeza-matthew is correct, this is just a warning. This change was made in firebase-admin v.7.0.0 so that you no longer need to provide firestore.settings({ timestampsInSnapshots: true }) in your code - it will default to this behavior with firebase-admin v.7.0.0. I hope this clears things up!
I have removed all the redundant firestore.settings({ timestampsInSnapshots: true }) configurations from my project and there are no error messages.
Solved. Thank you!
@dbacinski awesome, glad to hear that! If you encounter any other problems, please don't hesitate to open a new issue.
Most helpful comment
I have updated dependencies to:
Now Timestamp is returned correctly :tada:.
But I am getting an error message:
The timestampsInSnapshots setting now defaults to true and you no longer need to explicitly set it. In a future release, the setting will be removed entirely and so it is recommended that you remove it from your firestore.settings() call now.Even thou firestore configuration is still in place:
Seams that admin configuration is not respected by functions which seam to be a root cause of this issue.