loopbackio / loopbackio/loopback-connector-postgresql

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

Open
#534 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
118
Forks
184
Avg merge
1d 22h
Merged PRs (30d)
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the validation code introduced by loopback-datasource-juggler pull request 1662 and reproduce the issue through a find() call on a PostgreSQL JSON field containing a top-level $ key. Done means SQL JSON equality queries no longer raise OPERATOR_NOT_ALLOWED_IN_QUERY while MongoDB extended-operator validation remains applicable.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, postgresql
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.