loopbackio / loopbackio/loopback-connector-postgresql

MongoDB extended operator rules erroneously applied to SQL databases and json bodies

Aperta
#534 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug
Lingua principale
JavaScript
Stelle
118
Fork
184
Merge medio
1g 22h
PR unite (30g)
5

Descrizione

NOTE: This is a bug in loopback-datasource-juggler, however the issue template there explicitly requests filing bugs in this project so 🤷

https://github.com/loopbackio/loopback-datasource-juggler/pull/1662 brought in some validation code that only is applicable to MongoDB, and is making certain operation on JSON properties/columns with SQL databases excessively difficult.

It is already impossible to do json equality searches out of the box due to #477, however that issue has a fairly straight forward workaround.

That workaround fails if the JSON object you are searching for contains any properties starting with a $ at the top level however, because they are interpreted as extended operators, even if they cannot possibly actually be such.

For example, pretend #477 was already fixed and you wrote this where expression:

{ where: { propertyName: { eq: { $foo: 'bar' } } } }

The $foo, AFAICT, cannot possibly be an operator because you already specified the eq operator.

Furthermore, if you're not using MongoDB, then this whole thing is moot anyways and these checks are inapplicable.

Steps to reproduce

  1. Create an entity type with a property of object type mapped to a SQL field of json type
  2. Insert a record that has a key in this property, at the top level, whose name starts with a $
  3. Attempt to do a find() call to locate this record using an equality match on that property

Current Behavior

  1. #477 gets in your way
  2. Even with the workaround for that, Loopback throws a OPERATOR_NOT_ALLOWED_IN_QUERY error and refuses to run your query

Expected Behavior

Loopback should be able to do property = ? queries on JSON fields against SQL databases.

Link to reproduction sandbox

WIP

Additional information

Same environment as #477

Related Issues

  • #477

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il codice di validazione introdotto dalla pull request 1662 di loopback-datasource-juggler e riproduci il problema tramite una chiamata a find() su un campo JSON PostgreSQL contenente una chiave $ di primo livello. Il lavoro è completato quando le query di uguaglianza JSON SQL non generano più OPERATOR_NOT_ALLOWED_IN_QUERY, mentre la validazione degli operatori estesi di MongoDB rimane applicabile.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, postgresql
Ambito
database
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.