parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Incorrect date type in LiveQuery

Open catalunha opened this issue 2 years ago • 2 comments

New Issue Checklist

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.

catalunha avatar May 12 '22 17:05 catalunha

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

dblythy avatar May 18 '22 00:05 dblythy

@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.

mtrezza avatar Mar 01 '23 08:03 mtrezza

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.

catalunha avatar Mar 01 '23 10:03 catalunha

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.

catalunha avatar Mar 01 '23 15:03 catalunha

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.

mtrezza avatar Mar 01 '23 21:03 mtrezza

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.

catalunha avatar Mar 04 '23 10:03 catalunha

Could you provide a minimal code example that others can run to replicate the issue?

mtrezza avatar Mar 04 '23 13:03 mtrezza

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

catalunha avatar Mar 04 '23 14:03 catalunha

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.

mtrezza avatar Mar 04 '23 23:03 mtrezza

🎉 This change has been released in version 6.1.0-alpha.5

parseplatformorg avatar Mar 06 '23 10:03 parseplatformorg

🎉 This change has been released in version 6.1.0-beta.2

parseplatformorg avatar May 01 '23 21:05 parseplatformorg

🎉 This change has been released in version 6.1.0

parseplatformorg avatar May 01 '23 21:05 parseplatformorg