loopbackio / loopbackio/loopback-datasource-juggler

v3.31.0 introduces bug

Open
#1,754 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted major regression
Dominant language
JavaScript
Stars
282
Forks
366
Avg merge
17h 4m
Merged PRs (30d)
10

Description

The following code works fine in v3.30.0:

```
const query = {
where: {
or: [
{ username: username },
{ email: username }
]
}
};
self.userModel.findOne(query, function (err, user) {
```

As of v.3.31.0, I get the following error:
```
Error: The where clause "abc@xyz.com" is not an object
at Function.ModelUtils._coerce (C:\apps\flexit\node_modules\loopback-datasource-juggler\lib\model-utils.js:369:11)
at Function.ModelUtils._coerce (C:\apps\flexit\node_modules\loopback-datasource-juggler\lib\model-utils.js:552:20)
at Function.ModelUtils._coerce (C:\apps\flexit\node_modules\loopback-datasource-juggler\lib\model-utils.js:394:14)
at Function.ModelUtils._normalize (C:\apps\flexit\node_modules\loopback-datasource-juggler\lib\model-utils.js:177:8)
at Function.find (C:\apps\flexit\node_modules\loopback-datasource-juggler\lib\dao.js:1529:10)
at Function.findOne (C:\apps\flexit\node_modules\loopback-datasource-juggler\lib\dao.js:1782:8)
at Strategy._verify (C:\apps\flexit\server\boot\authentication.js:288:36)
at Strategy.authenticate (C:\apps\flexit\node_modules\passport-local\lib\strategy.js:90:12)
at attempt (C:\apps\flexit\node_modules\passport\lib\middleware\authenticate.js:361:16)
at authenticate (C:\apps\flexit\node_modules\passport\lib\middleware\authenticate.js:362:7)
```

Looks like something broke in the _coerce function.

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 in lib/model-utils.js at the _coerce calls around lines 369, 394, and 552, then follow normalization from lib/model-utils.js into findOne in lib/dao.js. Reproduce the provided or query on v3.31.0 and compare it with v3.30.0. Done means the query accepts the same object form without reporting the email value as a non-object.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.