Query `containsAllStartingWith` returns wrong results with Postgres when the number of matching array elements differs from the number of prefixes
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 84/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, postgresql
Línea de trabajo
Empieza por src/Adapters/Storage/Postgres/sql/array/contains-all-regex.sql y compara su lógica de coincidencia con la semántica de MongoDB descrita en el issue. Después, localiza el spec existente containsAllStartingWith single regex value should return corresponding matching results y comprueba los casos en los que varios elementos del array coinciden con un prefijo o un elemento coincide con varios prefijos. Se considera terminado cuando Postgres coincide con MongoDB en los tres ejemplos del issue.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- JavaScript
- Estrellas
- 21.4k
- Forks
- 4.8k
- Merge medio
- 7 h 8 min
- PR fusionados (30 d)
- 65
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de parse-community/parse-server
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
parse-community/parse-server#10870 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Unsupported `__op` value in a write request returns HTTP 500Posiblemente ocupada @RagedPanda la tomó hace 7 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
parse-community/parse-server#10841 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Query with an include path through an inherited object member fails with an internal server errorPosiblemente ocupada @charan-rathore la tomó hace 17 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
parse-community/parse-server#10795 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
parse-community/parse-server#10794 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Add MongoDB 9 supportPosiblemente ocupada @ga262 la tomó hace 31 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
parse-community/parse-server#10750 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de parse-community/parse-server
Issues similares
-
Jump in core size from v2.11.2Posiblemente ocupada @caolan-tether la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
holepunchto/hyperbee2#126 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
521xueweihan/HelloGitHub#4270 ·
-
Adopt browserslistrcAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
accessibility bug embed
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
quarto-dev/quarto-cli#15306 ·
Los mantenedores suelen responder en 1 día
-
502 on Node 26: ERR_INVALID_ARG_VALUE: Setting the TLS ServerName to an IP address is not permittedAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100