Fix item.read hook not firing for readByQuery #6645
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As reported by @lluishi93 in #6622 the current implementation of the
item.read
hook is flawed, as it doesn't get called with certain read actions.I've moved the calling of the hook to the
readByQuery
method (which gets called byreadOne
andreadMany
), but there is still a problem. Normally, the hook gets called as follows:In
readByQuery
, however, thekeys
array is not available, as it consumes a query, already with the keys implemented.I see several options:
Make an exception and don't return
item
herePass keys as an additional parameter to
readByQuery
; The significant drawback here is thatreadByQuery
is called from a lot of places in the codebase, and I feel like this would provide some 'code smell'Retrieve from the query as follows:
To be fair, this feels like a hack to me.
Return to state before Add support for
read
hooks onitems
#6341, as there's no proper fix at the moment.Would love to hear your opinions.
Fixes #6622