parse-server
parse-server copied to clipboard
Incorrect date type in LiveQuery
New Issue Checklist
- [ x] I am not disclosing a vulnerability.
- [ x] I am not just asking a question.
- [ x] I have searched through existing issues.
- [x ] I can reproduce the issue with the latest version of Parse Server and the Parse Flutter SDK.
Issue Description
if I build this query:
query.exists('birthDate');
See the output:
catalunha@pop-os:~/myapp/contactlist01js$ node index.js
open...
{
birthDate: { __type: 'Date', iso: '2022-05-11T23:48:00.000Z' },
name: 'Ana',
isMan: false,
createdAt: '2022-05-11T23:48:28.834Z',
updatedAt: '2022-05-11T23:48:28.834Z',
objectId: 'GxxCRLf9Vo'
}
{
name: 'Barros',
isMan: false,
createdAt: '2022-05-11T23:48:51.054Z',
updatedAt: '2022-05-12T00:20:34.344Z',
birthDate: { __type: 'Date', iso: '2022-05-12T00:20:00.000Z' },
objectId: 'EDhtmzJnGR'
}
contact.id: EDhtmzJnGR | leave...
{
birthDate: { __type: 'Date', iso: '2022-05-11T23:48:00.000Z' },
name: 'Ana',
isMan: false,
createdAt: '2022-05-11T23:48:28.834Z',
updatedAt: '2022-05-11T23:48:28.834Z',
objectId: 'GxxCRLf9Vo'
}
contact.id: EDhtmzJnGR | enter...
{
birthDate: { __type: 'Date', iso: '2022-05-11T23:48:00.000Z' },
name: 'Ana',
isMan: false,
createdAt: '2022-05-11T23:48:28.834Z',
updatedAt: '2022-05-11T23:48:28.834Z',
objectId: 'GxxCRLf9Vo'
}
{
name: 'Barros',
isMan: false,
createdAt: '2022-05-11T23:48:51.054Z',
updatedAt: '2022-05-12T00:25:34.959Z',
birthDate: '2022-05-12T00:25:00.000Z',
objectId: 'EDhtmzJnGR'
}
As the column/field is involved in the query, Parse returns it in String format and not Date. Strange agree?
Steps to reproduce
const Parse = require('parse/node');
Parse.serverURL = '...';
Parse.initialize('...','...');
const main = async ()=>{
const query = new Parse.Query('Contact');
query.exists('birthDate');
const subscribe = await query.subscribe();
let contacts = {};
const printContacts = ()=>{
console.log();
Object.keys(contacts).forEach(id=>{
console.log(contacts[id].toJSON());
});
console.log();
};
subscribe.on('open', async ()=>{
console.log('open...');
contacts = (await query.find()).reduce((contacts,contact)=>({
...contacts,
[contact.id]: contact
}),contacts);
printContacts();
});
subscribe.on('create',(data)=>{
console.log(`Data: ${data.id} | create...`);
contacts[data.id]=data;
printContacts();
});
subscribe.on('update',(data)=>{
console.log(`Data: ${data.id} | update...`);
contacts[data.id]=data;
printContacts();
});
subscribe.on('enter',(data)=>{
console.log(`Data: ${data.id} | enter...`);
contacts[data.id]=data;
printContacts();
});
subscribe.on('leave',(data)=>{
console.log(`Data: ${data.id} | leave...`);
delete contacts[data.id];
printContacts();
});
subscribe.on('delete',(data)=>{
console.log(`Data: ${data.id} | delete...`);
delete contacts[data.id];
printContacts();
});
subscribe.on('closed',()=>{
console.log('closed...');
});
};
main();
Actual Outcome
But Parse's default Date format is: birthDate: { __type: 'Date', iso: '2022-05-11T23:48:00.000Z' }, Just because this column goes to query it has another type, in this case String ? birthDate: '2022-05-12T00:25:00.000Z', I find this complicated! Because regardless of my consumption it is reporting data in different formats. Do you agree?
Expected Outcome
In any case, inside or outside of liveQuery, the date format is: birthDate: { __type: 'Date', iso: '2022-05-11T23:48:00.000Z' },
Environment
Parse Flutter SDK
- SDK version:
parse_server_sdk_flutter: ^3.1.0
- Operating system version:
Linux PopOS
Server I'm using back4app.com
- Parse Server version:
4.5.0
Logs
There is no error. Just the return with different types.
Thanks for opening this issue!
- 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.
Possibly related to #7082
@catalunha Could you confirm that this issue has been fixed? A related issue has been fixed, see https://github.com/parse-community/parse-server/issues/7082.
Hello @mtrezza , thank you for your attention. After the rich updates I didn't reuse liveQuery. I will review the issue and report it here.
Hello @mtrezza , I just performed a new test cycle. I believe the error persists. I'm using Parse Version 4.5.0 See that when starting the liveQuery. It reads the Date type as object. See below:
open...
{
typeDateTime: { __type: 'Date', iso: '2023-03-01T15:48:00.000Z' },
typeArray: [ '1', 'um' ],
typeNumber: 4,
typeString: 'um',
typeBoolean: true,
createdAt: '2023-03-01T14:48:41.507Z',
updatedAt: '2023-03-01T14:51:16.253Z',
objectId: 'TIUzNT3L8d'
}
2023-03-01T15:48:00.000Z
object
But after an update it returns as a string. See below:
Data: TIUzNT3L8d | update...
{
typeDateTime: '2023-03-01T15:48:00.000Z',
typeArray: [ '1', 'um' ],
typeNumber: 4.1,
typeString: 'um',
typeBoolean: true,
createdAt: '2023-03-01T14:48:41.507Z',
updatedAt: '2023-03-01T14:53:22.813Z',
objectId: 'TIUzNT3L8d'
}
2023-03-01T15:48:00.000Z
string
I changed to Parse Version 5.2.3 and the same thing happens.
Thanks for testing, does this still occur with the latest alpha version of Parse Server? Maybe you could just submit a PR with a failing test so we can better see what this is about.
How I would like to have a little more knowledge to cooperate with you in this incredible journey of mutual cooperation in such an interesting project that is Parse. I'm really excited about him. I have cooperated in other levels within my limitations, but how to cooperate here I'm still a bit lost. If you can, because I believe you want to but time doesn't allow it, let me know a roadmap of knowledge that I need to have to cooperate here, I would appreciate it and dedicate myself to studying each route on the roadmap until I can cooperate with this team here. But your request above is totally incomprehensible to me on how to solve it to help you. Sorry, thanks for everything and I'm willing to learn and cooperate.
Could you provide a minimal code example that others can run to replicate the issue?
Here it is. Is it enough?
package.json
{
"dependencies": {
"parse": "^3.5.1"
},
"name": "youB4AAppName",
"version": "1.0.0",
"main": "index.js",
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
./index.js
const Parse = require('parse/node');
Parse.serverURL = 'https://youB4AAppName.b4a.io';
Parse.initialize('applicationId','javaScriptKey');
const main = async ()=>{
const query = new Parse.Query('Genre');
query.exists('typeDateTime');
const subscribe = await query.subscribe();
let contacts = {};
const printContacts = ()=>{
console.log('printContacts+++');
Object.keys(contacts).forEach(id=>{
console.log(contacts[id].toJSON());
console.log(contacts[id].get('typeDateTime'))
console.log(typeof contacts[id].get('typeDateTime'))
});
console.log('printContacts---');
};
subscribe.on('open', async ()=>{
console.log('open...');
contacts = (await query.find()).reduce((contacts,contact)=>({
...contacts,
[contact.id]: contact
}),contacts);
printContacts();
});
subscribe.on('create',(data)=>{
console.log(`Data: ${data.id} | create...`);
contacts[data.id]=data;
printContacts();
});
subscribe.on('update',(data)=>{
console.log(`Data: ${data.id} | update...`);
contacts[data.id]=data;
printContacts();
});
subscribe.on('enter',(data)=>{
console.log(`Data: ${data.id} | enter...`);
contacts[data.id]=data;
printContacts();
});
subscribe.on('leave',(data)=>{
console.log(`Data: ${data.id} | leave...`);
delete contacts[data.id];
printContacts();
});
subscribe.on('delete',(data)=>{
console.log(`Data: ${data.id} | delete...`);
delete contacts[data.id];
printContacts();
});
subscribe.on('closed',()=>{
console.log('closed...');
});
};
main();
running.
$ node index.js
Yes thanks, could you try this with the latest versions of Parse Server and the Parse Flutter SDK? We want to make sure the bug hasn't been fixed already.
🎉 This change has been released in version 6.1.0-alpha.5
🎉 This change has been released in version 6.1.0-beta.2
🎉 This change has been released in version 6.1.0