eq object (JSON columns) doesn't work
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, postgresql
- Ambito
- databases
Direzione di ricerca
Inizia in lib/postgresql.js, nelle posizioni relative al parsing degli operatori e a buildExpression citate nel report, quindi esamina la logica di base correlata in loopback-connector/lib/sql.js. Riproduci la query di uguaglianza su una colonna JSON con PostgreSQL e traccia il modo in cui il valore dell’oggetto diventa SQL. Il lavoro è completato quando i valori degli oggetti nelle clausole where generano SQL valido e restituiscono i record corrispondenti, con una copertura di regressione nei test pertinenti del connettore.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Steps to reproduce
- Create a model that has an object column, mapped as a JSON type in PostgreSQL
- Try to do a
findsearching for a full value in that property/column, e.g.const objectValue = {a: 1, b: 2};and thenrepo.find({where: {objectProperty: objectValue}})orrepo.find({where: {objectProperty: {eq: objectValue}}})
Current Behavior
- The
{objectProperty: {eq: value}}is translated down into{objectProperty: value} - This line assumes that, if the value is an object, it must contain exactly one field that must be an operator: https://github.com/strongloop/loopback-connector-postgresql/blob/master/lib/postgresql.js#L654
- It tries to map e.g.
aas an operator name - The
buildExpressionoperator switch hits itsdefaultclause which delegates to the base class inloopback-connector: https://github.com/strongloop/loopback-connector-postgresql/blob/master/lib/postgresql.js#L540-L543 - That base class method has a
switchwith nodefaultclause, so it doesn't throw any errors and just concatenates the column name with the placeholder for the value: https://github.com/strongloop/loopback-connector/blob/master/lib/sql.js#L969 - And so it generates invalid SQL that looks like
"columName"$1
Expected Behavior
- I should be able to use object values in where clauses if the property contains object values
Link to reproduction sandbox
WIP -- NB: encountering this in an LB4 app
Additional information
- Running on
linux x64 12.22.1 npm lsdoesn't work withrush, but usingloopback-connector-postgresqlv5.0.1, withloopback-connectorv4.11.1, and the following LB4 components:"@loopback/boot": "2.2.0""@loopback/context": "3.9.3""@loopback/core": "2.5.0""@loopback/metadata": "2.2.6""@loopback/openapi-v3": "3.3.1""@loopback/openapi-v3-types": "1.2.1""@loopback/repository": "2.4.0""@loopback/rest": "4.0.0""@loopback/rest-explorer": "2.2.0"
Related Issues
Haven't found any yet
Workaround
Create a custom class to represent the value, and then have the equality comparison value use that, e.g. something like this, but without the prototype pollution vulnerabilities:
class JSONWrapper {
[k: string]: any
constructor(value: any) {
Object.assign(this, value)
}
}
// elsewhere:
repo.find({where: {objectProperty: new JSONWrapper(objectValue)}});
This causes the expression.constructor === Object check to fail, and so it doesn't try to unwrap the value
- Lingua principale
- JavaScript
- Stelle
- 118
- Fork
- 184
- Merge medio
- 1g 22h
- PR unite (30g)
- 5
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di loopbackio/loopback-connector-postgresql
-
Partial JSON Update Apertafeature
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
loopbackio/loopback-connector-postgresql#748 · 1 commento ·
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 38/100
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
loopbackio/loopback-connector-postgresql#732 · 1 commento ·
Tutte le issue di loopbackio/loopback-connector-postgresql
Issue simili
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Improve Title Support Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
georgestephanis/p2026#40 ·
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Margaret-Petersen/food-delivery-app-clone-react-native#1981 ·