Skip to content
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

Incorrect date type in LiveQuery #8005

Closed
catalunha opened this issue May 12, 2022 · 13 comments · Fixed by #8456
Closed

Incorrect date type in LiveQuery #8005

catalunha opened this issue May 12, 2022 · 13 comments · Fixed by #8456
Labels
state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@catalunha
Copy link

catalunha commented May 12, 2022

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.

@parse-github-assistant
Copy link

parse-github-assistant bot commented May 12, 2022

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.

@mtrezza mtrezza added the type:bug Impaired feature or lacking behavior that is likely assumed label May 17, 2022
@mtrezza mtrezza transferred this issue from parse-community/Parse-SDK-Flutter May 17, 2022
@mtrezza mtrezza changed the title Date change type in query Incorrect date type in LiveQuery May 17, 2022
@parse-community parse-community deleted a comment from catalunha May 17, 2022
@mtrezza mtrezza reopened this May 17, 2022
@dblythy
Copy link
Member

dblythy commented May 18, 2022

Possibly related to #7082

@mtrezza
Copy link
Member

mtrezza commented Mar 1, 2023

@catalunha Could you confirm that this issue has been fixed? A related issue has been fixed, see #7082.

@catalunha
Copy link
Author

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
Copy link
Author

catalunha commented Mar 1, 2023

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.

@mtrezza
Copy link
Member

mtrezza commented Mar 1, 2023

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.

@catalunha
Copy link
Author

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.

@mtrezza
Copy link
Member

mtrezza commented Mar 4, 2023

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

@catalunha
Copy link
Author

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

@mtrezza
Copy link
Member

mtrezza commented Mar 4, 2023

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.

@parseplatformorg
Copy link
Contributor

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

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Mar 6, 2023
@parseplatformorg
Copy link
Contributor

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

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label May 1, 2023
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.1.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants