loopbackio / loopbackio/loopback-connector-postgresql

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

Ouverte
#534 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

bug
Langage dominant
JavaScript
Étoiles
118
Forks
184
Merge moyen
1 j 22 h
PR mergées (30 j)
5

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par le code de validation introduit par la pull request 1662 de loopback-datasource-juggler et reproduisez le problème avec un appel à find() sur un champ JSON PostgreSQL contenant une clé $ au niveau supérieur. Le travail est terminé lorsque les requêtes d’égalité JSON SQL ne lèvent plus OPERATOR_NOT_ALLOWED_IN_QUERY, tandis que la validation des opérateurs étendus de MongoDB reste applicable.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, postgresql
Domaine
database
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.