ParseServer with Aurora Postgres saves 0 and decimals in arrays as string
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
- Create an array with 0s or decimals inside. e.g. [0, 1.1, 2, 3, 4, 5]
- Set an object with that array. e.g. record.set('array', [0, 1.1, 2, 3, 4, 5]);
- 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
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
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
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"]
@jwenBai Thanks for reporting. I submitted a PR with a fix https://github.com/parse-community/parse-server/pull/5251