firebase-functions v2.2.0 firestore trigger Date instead of Timestamp
See original GitHub issueRelated issues
https://github.com/firebase/firebase-functions/issues/285
[REQUIRED] Version info
firebase-functions: v2.2.0
[REQUIRED] Test case
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()
}
[REQUIRED] Expected behavior
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
[REQUIRED] Actual behavior
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
Were you able to successfully deploy your functions?
yes
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Cloud Firestore triggers | Cloud Functions for Firebase
Note: Cloud Firestore events will trigger only on document changes. An update to a Cloud Firestore document, where data is unchanged (a no-op...
Read more >Writing to firestore in firebase cloud-function shifts my dates
Calling cloud function from client side and passing 2 dates which are converted toISO8601String. Printing dates to console while executing cloud ...
Read more >Google Cloud Firestore Triggers | Cloud Functions ...
Google Cloud Firestore Triggers · Waits for changes to a particular document. · Triggers when an event occurs and performs its tasks. ·...
Read more >Dynamic Scheduled Background Jobs in Firebase
Trigger Cloud Functions based on cron time intervals and create a task ... performAt when to execute the task as a Firestore timestamp....
Read more >Firebase / Firestore Integration
To write back to timestamp fields in Firestore (and avoid setting them as strings), you'll need to convert your data to a date...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have updated dependencies to:
Now Timestamp is returned correctly 🎉.
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.
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.