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

ParseServer with Aurora Postgres saves 0 and decimals in arrays as string #5239

Closed
jorgelrst opened this issue Dec 14, 2018 · 4 comments
Closed
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@jorgelrst
Copy link

Issue Description

On Parse using Aurora Postgres:
When saving an array with either a 0 or some decimal value (ex. 1.1) to a field of type Array, those number values are automatically converted to strings somehow. Any other integer is fine. For example, the array becomes ["0", "1.1", 2, 3, 4, 5] when expecting [0, 1.1, 2, 3, 4, 5]. I have tried a lot of weird and random things to try to force the value to an int (like using parseInt(0)), but nothing seems to work. The save is done using .set (for example: record.set('array', [0, 1.1, 2, 3, 4, 5])).

Steps to reproduce

  1. Create an array with 0s or decimals inside. e.g. [0, 1.1, 2, 3, 4, 5]
  2. Set an object with that array. e.g. record.set('array', [0, 1.1, 2, 3, 4, 5]);
  3. Save the object e.g. record.save()

Expected Results

record of Table/Class to have [0, 1.1, 2, 3, 4, 5] set in 'array' field

Actual Outcome

["0", "1.1", 2, 3, 4, 5]

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : 2.8.2
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): AWS/Localhost
  • Database

    • MongoDB version: N/A, Aurora PostgreSQL 10.4
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): [AWS]

Logs/Trace

N/A

@flovilmart
Copy link
Contributor

Thanks for reporting the issue!

The Postgres adapter has a special debugger that traces all the sql commands. You can enable it with setting the environment variable PARSE_SERVER_LOG_LEVEL=debug

@dplewis
Copy link
Member

dplewis commented Dec 14, 2018

I tried this with Postgres 10 and Aurora PG 10.4 and this works fine for me.

  • I'm running the latest version of parse

Can you run the following test?

  fit('can save decimal to array', async () => {
    const data = [0, 1.1, 1, -2, 3];
    const obj1 = new TestObject();
    obj1.set('array', data);
    await obj1.save();
    equal(obj1.get('array'), data);

    const query = new Parse.Query(TestObject);
    const result = await query.get(obj1.id);
    equal(result.get('array'), data);

    const results = await query.find();
    equal(results[0].get('array'), data);
  });

https://github.com/parse-community/parse-server/blob/master/CONTRIBUTING.md

@dplewis dplewis added the type:bug Impaired feature or lacking behavior that is likely assumed label Dec 14, 2018
@jwenBai
Copy link

jwenBai commented Dec 18, 2018

When I create the object, then retrieve it, and then set array attribute, I got the same issue. But when I set the array on the object without retrieving it, it is fine.

function test() {
  const TestTable = Parse.Object.extend('testTable');
  const obj1 = new TestTable();
  const data1 = [0, 1.1, 1, -2, 3];
  obj1.set('array', data1);
  obj1.save().then((obj) => {
    const testQuery = new Parse.Query('testTable');
    testQuery.equalTo('objectId', obj.id);
    testQuery.first().then((testObj) => {
      const data2 = [0, 1.1, 1, -2, 3, 4];
      testObj.set('array', data2);
      testObj.save();
    });
  });

this is the one that doesn't work properly. the final result is [ "0", "1.1", "1", "-2", "3", "4"]

@dplewis
Copy link
Member

dplewis commented Dec 18, 2018

@jwenBai Thanks for reporting. I submitted a PR with a fix #5251

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

4 participants