Closed mgabeler-lee-6rs closed 4 years ago
This is closely related to https://github.com/strongloop/loopback-next/issues/2788
findById
and findOne
are broken by the same issue. It's possible to monkey-patch around the find
and findOne
bugs by overriding the methods and inserting the extra layer of filter: {...}
, but the way findById
is written, that trick doesn't work and monkey-patching around its bug requires a more complex solution.
Actually, monkey-patching findOne
is hard too
Also finding that 404
handling for even a basic findById
(which does issue the correct REST request) is broken -- it returns the HTTP exception, fails to translate it into an EntityNotFoundError
@mgabeler-lee-6rs for me this error has stopped the project build process and only when I remove the block which contains the .find
call... only then the project can run. Even, I was trying this in the Todo and the TodoList examples in the official doc. Even in any new project that I start 0and generate a CRUD controller, as well as your demo for this issue. I am currently using @loopback/core: "^1.7.1"
, I wanted to try using Loopback in my upcoming project but I can't get past this... Any thoughts?
Here's a gist with a slightly simplified version of my monkey patching: https://gist.github.com/mgabeler-lee-6rs/6f30a3e117182060cc88a8d20e6ed914
The idea is that you extend this base class instead of the normal one that it extends when creating a repository that uses a rest datasource under the hood. And only when it's using rest under the hood -- this will almost certainly break things if you use any other datasource.
I would caution if you adopt something like this in your own code base to write very careful acceptance tests, and not to assume any methods not "fixed" are working unless you have such tests that prove it. Speaking from experience, it is very easy to make mistakes in the acceptance tests and think you have patched the methods correctly when you have not.
@raymondfeng PTAL
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
still broken as described
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS
file at the top-level of this repository.
Description/Steps to reproduce
repo.find
with a filter parameterLink to reproduction sandbox
https://github.com/mgabeler-lee-6rs/lb4-rest-filter
Repro steps for the sandbox app:
npm install
npm start
rest-bug-demo
endpointThe app:
POST
endpoint that will invokefind
on the REST datasource with a query filter, and return the resultsExpected result
GET
request is made to/Model?filter...
instead of/Model?where...
and thus only the requested objects are returnedActual result
All objects in the repository are returned regardless of filter. Filter options like
include
andfields
are ignored just likewhere
is.