parse-community / parse-community/parse-server
`.equalTo` no working in string Arrays when using PostgreSQL
Open
Nobody has claimed this yet.
type:bug
- Dominant language
- JavaScript
- Stars
- 21.4k
- Forks
- 4.8k
- Avg merge
- 7h 45m
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
- I can reproduce the issue with the latest version of Parse Server.
Issue Description
When using equalTo on an Array of Strings with a PostgreSQL DB, an error gets thrown.
Might be related to #6403
Seems to be an encoding issue for Postegres queries.
Steps to reproduce
- Set up Parse with PostgreSQL
- Add a new Class with an
ArrayField and add strings (it's stored asjsonbon the db) - Try to access it via
equalTo
Using parse/node
"use strict";
const Parse = require("parse/node");
Parse.initialize("appId");
Parse.serverURL = "http://localhost:1337/parse/";
Parse.Config.get()
.then((config) => {
console.debug(`Parse API Connection established.`);
})
.catch(console.error)
.then(() => new Parse.Query("testClass"))
.then((qry) => qry.get("bPWn1BIwN3"))
.then((res) => console.log("actual data:", res.get("stringArray")))
.then(() => new Parse.Query("testClass"))
.then((qry) => {
qry.equalTo("stringArray", "stringOne");
return qry.find();
})
.then(() => console.log("will not be triggered"))
.catch((err) => console.error("we fail with:", err));
$ npm run start
> test-setup@1.0.0 start
> node ./index.js
Parse API Connection established.
actual data: [ 'stringOne', 'stringTwo' ]
we fail with: [ParseError: [object Object]
at handleError (/home/bastian/datenhalde/pgTest/node_modules/parse/lib/node/RESTController.js:426:17)
at processTicksAndRejections (node:internal/process/task_queues:94:5)] {
code: 1
}
on the Parse Dashboard:
const qry = new Parse.Query("test")
qry.equalTo("stringArray", "stringOne");
console.log(await qry.find());
Output:
{
"message": {
"length": 165,
"name": "error",
"severity": "ERROR",
"code": "22P02",
"detail": "Token \"stringOne\" is invalid.",
"position": "44",
"where": "JSON data, line 1: stringOne",
"file": "jsonfuncs.c",
"line": "617",
"routine": "json_ereport_error"
},
"name": "Error",
"stack": "s@http://0.0.0.0:4040/bundles/dashboard.bundle.js:75:630545\nt@http://0.0.0.0:4040/bundles/dashboard.bundle.js:75:624686\nd</n<@http://0.0.0.0:4040/bundles/dashboard.bundle.js:16:97361\nr@http://0.0.0.0:4040/bundles/dashboard.bundle.js:16:97493\nhandleError@http://0.0.0.0:4040/bundles/dashboard.bundle.js:75:674336\n"
}
using
Server
- Parse Server version:
4.5.0 - Operating system:
5.10.23-1-MANJARO (localhost) - Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc):
localhost
Database
- System (MongoDB or Postgres):
Postgres - Database version:
13 - Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc):
localhost
Client
- SDK (iOS, Android, JavaScript, PHP, Unity, etc):
parse/node / parse dashboard - SDK version:
3.1 / 2.1.0
Logs
Parse Server Logs:
verbose: REQUEST for [GET] /parse/classes/test: {
"where": {
"stringArray": "stringOne"
}
} {"method":"GET","url":"/parse/classes/test","headers":{"user-agent":"node-XMLHttpRequest, Parse/js3.1.0 (NodeJS 15.11.0)","accept":"*/*","content-type":"text/plain","host":"localhost:1337","content-length":"197","connection":"close"},"body":{"where":{"stringArray":"stringOne"}}}
error: Parse error: error: invalid input syntax for type json {"code":1,"stack":"Error: error: invalid input syntax for type json\n at /path/to/local/parse/node_modules/parse-server/lib/Controllers/DatabaseController.js:1170:21\n at processTicksAndRejections (node:internal/process/task_queues:94:5)"}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the PostgreSQL 13 failure with the provided parse/node or Dashboard query, then inspect parse-server/lib/Controllers/DatabaseController.js around line 1170 and the JSONB query handling it reaches. Done means equalTo on a string array returns matching objects without PostgreSQL's invalid JSON input error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, postgresql
- Domain
- api, backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100