-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query fails due to "Tried to encode an invalid date." #3370
Comments
I created a fix but I am not sure if it is the best solution. If you run Nodechef Parse Server version 2.2.25 this will not be a cloud code issue. Not sure what their fix is. However, you will have to make edits to your local server build and JS SDK.
Oldif (value.__type === 'Date') { New Hackif (value.__type === 'Date') { Data IssueWithin an array I have objects that contain date objects. The problem is that the iso value is another date object, not an iso value. I am unclear if the data problem was something I did incorrectly or was a parse bug or ... Bad Date Good Date Data FixI am unclear what the best method is to repair the the "damaged data". I have 3 classes with this problem. I will most likely do a query in which I check if the offending fields have data (exists), select only those fields and re-save the returned arrays. |
@designunion thanks for reporting the issue! |
@designunion Matt here, I just submitted a pull request for this. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Query fails when an array column contains objects with dates. I have been able to isolate the data that generates the problem (see below). The problem does not occur with hosted-parse. The problem seems to be due to node modules based on the log information (see below).
The date formatting seems to be the issue:
The following is a closed issue which seems related but there was no resolution.
#1077
Steps to reproduce
var Obj = Parse.Object.extend("Clock");
var query = new Parse.Query(Obj);
query.equalTo("objectId","2iVREi5Kiu");
query.find().then(function(result) {
res.success(result);
}, function(error) {
res.error(error);
});
OR
query.get("2iVREi5Kiu").then(function(result) {
console.log(result);
}, function(error) {
console.log(error);
});
Expected Results
I expect the result field "history" to contain an array with an object that contains 2 dates. Instead the query fails.
[{ date: [should be a valid date],
event: 'Clock In - Sick Leave',
from: 'None',
to: [should be a valid date],
type: 'date',
who: 'Brian Login' }]
Actual Outcome
Console Log - Cloud
{code: 141, message: {}}
Console Log - Local
{className: "Error", _objCount: 8}
Console Log - Server
[{ date: Invalid Date,
event: 'Clock In - Sick Leave',
from: 'None',
to: Invalid Date,
type: 'date',
who: 'Brian Login' }]
CURL Results
curl -X GET
-H "X-Parse-Application-Id: xxx"
-H "X-Parse-Master-Key: xxx"
-G
--data-urlencode "where={"objectId":"2iVREi5Kiu"}"
https://xxx.nodechef.com/parse/classes/Clock
[{
"date": {
"__type": "Date",
"iso": {
"__type": "Date",
"iso": "2014-11-15T07:35:03.000Z"
}
},
"event": "Clock In - Sick Leave",
"from": "None",
"to": {
"__type": "Date",
"iso": {
"__type": "Date",
"iso": "2014-11-14T21:00:00.000Z"
}
},
"type": "date",
"who": "Brian Login"
}]
Stored Data - That Does Not Work
[{
date: {
__type: "Date",
iso: ISODate("2014-11-15T07:35:03Z")
},
event: "Clock In - Sick Leave",
from: "None",
to: {
iso: ISODate("2014-11-14T21:00:00Z"),
__type: "Date"
},
type: "date",
who: "Brian Login"
}]
Stored Data - That Will Work
[{
who: "Brian Login",
date: {
__type: "Date",
iso: "2014-11-15T02:35:03.026Z"
},
event: "Clock In - Sick Leave",
from: "None",
to: {
__type: "Date",
iso: "2014-11-14T16:00:00.000Z"
},
type: "date"
}]
Environment Setup
Server
Database
Logs/Trace
Error generating response. ParseError {
code: 141,
message:
Error: Tried to encode an invalid date.
at encode (/Users/brianmcgrath/parse-server-example/node_modules/parse-server/node_modules/parse/lib/node/encode.js:81:13)
at encode (/Users/brianmcgrath/parse-server-example/node_modules/parse-server/node_modules/parse/lib/node/encode.js:98:19)
at /Users/brianmcgrath/parse-server-example/node_modules/parse-server/node_modules/parse/lib/node/encode.js:91:14
at Array.map (native)
at encode (/Users/brianmcgrath/parse-server-example/node_modules/parse-server/node_modules/parse/lib/node/encode.js:90:18)
at exports.default (/Users/brianmcgrath/parse-server-example/node_modules/parse-server/node_modules/parse/lib/node/encode.js:16:10)
at Object.commitServerChanges (/Users/brianmcgrath/parse-server-example/node_modules/parse-server/node_modules/parse/lib/node/ObjectStateMutations.js:161:39)
at Object.commitServerChanges (/Users/brianmcgrath/parse-server-example/node_modules/parse-server/node_modules/parse/lib/node/UniqueInstanceStateController.js:162:24)
at ParseObjectSubclass.value (/Users/brianmcgrath/parse-server-example/node_modules/parse-server/node_modules/parse/lib/node/ParseObject.js:394:23)
at Function.value (/Users/brianmcgrath/parse-server-example/node_modules/parse-server/node_modules/parse/lib/node/ParseObject.js:1554:9) } code=141,
[object Object]
The text was updated successfully, but these errors were encountered: