Query `containsAllStartingWith` returns wrong results with Postgres when the number of matching array elements differs from the number of prefixes
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 84/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- javascript, postgresql
Piste de recherche
Commence par src/Adapters/Storage/Postgres/sql/array/contains-all-regex.sql et compare sa logique de correspondance avec la sémantique de MongoDB décrite dans l’issue. Repère ensuite le spec existant containsAllStartingWith single regex value should return corresponding matching results et vérifie les cas où plusieurs éléments du tableau correspondent à un préfixe ou où un élément correspond à plusieurs préfixes. Le travail est terminé lorsque Postgres donne les mêmes résultats que MongoDB pour les trois exemples de l’issue.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
New Issue Checklist
- Report security issues confidentially.
- Any contribution is under this license.
- Before posting search existing issues.
Issue Description
With the Postgres adapter, containsAllStartingWith (REST: $all with ^\Q...\E prefix regexes on an Array field) is implemented by the SQL helper array_contains_all_regex in src/Adapters/Storage/Postgres/sql/array/contains-all-regex.sql. The helper counts the array elements that match any of the patterns and compares that count with the number of patterns:
SELECT RES.CNT = jsonb_array_length("values")
FROM (SELECT COUNT(*) as CNT FROM jsonb_array_elements_text("array") as elt
WHERE elt LIKE ANY (SELECT jsonb_array_elements_text("values"))) as RES
This is not the semantics of the operator on MongoDB ($all: [/^\Qa\E/, ...]: every pattern must match at least one element). The count comparison gives wrong results whenever the number of matching elements differs from the number of patterns:
- False negative when more elements match than patterns were given:
['aaa', 'ab']with prefixa→ 2 matching elements ≠ 1 pattern →false. - False negative when one element satisfies several patterns:
['aaa']with prefixesaandaa→ 1 ≠ 2 →false. - False positive when several elements match one pattern while another pattern matches nothing:
['aaa', 'abb']with prefixesaandb→ 2 = 2 →true, although no element starts withb.
MongoDB returns the opposite result in all three cases. The existing spec containsAllStartingWith single regex value should return corresponding matching results passes on Postgres only because its test data has exactly one matching element per object.
Steps to reproduce
const object = new Parse.Object('TestObject');
object.set('strings', ['aaa', 'ab']);
await object.save();
const query = new Parse.Query('TestObject');
query.containsAllStartingWith('strings', ['a']);
const results = await query.find();
REST equivalent: where={"strings":{"$all":[{"$regex":"^\\Qa\\E"}]}}.
SQL-level check against the test database (the helper is created by the adapter):
SELECT array_contains_all_regex('["aaa","ab"]'::jsonb, '["a%"]'::jsonb); -- false, expected true
SELECT array_contains_all_regex('["aaa"]'::jsonb, '["a%","aa%"]'::jsonb); -- false, expected true
SELECT array_contains_all_regex('["aaa","abb"]'::jsonb, '["a%","b%"]'::jsonb); -- true, expected false
Actual Outcome
Postgres: the query in the example returns no results; MongoDB returns the object. The SQL helper returns the values noted in the comments above.
Expected Outcome
The same results as MongoDB: an object matches when every prefix matches at least one array element, independent of how many elements match. For example, count the patterns that have at least one matching element and compare that count with the number of patterns.
Environment
Server
- Parse Server version:
9.11.1-alpha.2 - Operating system: macOS 27.0.1
- Local or remote host: local
Database
- System (MongoDB or Postgres): Postgres
- Database version: PostgreSQL 16 with PostGIS 3.5 (
postgis/postgis:16-3.5) - Local or remote host: local Docker
Client
- SDK (iOS, Android, JavaScript, PHP, Unity, etc): JavaScript / REST
- SDK version:
8.7.0
Logs
n/a
- Langage dominant
- JavaScript
- Étoiles
- 21.4k
- Forks
- 4.8k
- Merge moyen
- 7 h 8 min
- PR mergées (30 j)
- 65
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de parse-community/parse-server
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
parse-community/parse-server#10870 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Unsupported `__op` value in a write request returns HTTP 500Peut-être pris @RagedPanda l’a pris il y a 9 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
parse-community/parse-server#10841 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Query with an include path through an inherited object member fails with an internal server errorPeut-être pris @charan-rathore l’a pris il y a 19 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
parse-community/parse-server#10795 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
parse-community/parse-server#10794 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Add MongoDB 9 supportPeut-être pris @ga262 l’a pris il y a 33 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
parse-community/parse-server#10750 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de parse-community/parse-server
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Fei2411/DeepSeek-Bot#1113 ·
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
arfct/timezone.fyi#19 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
fastify/fastify-http-proxy#493 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
eliasstravik/herdr-projects#785 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
tensorflow/tfjs#8754 ·