-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local API: req.locale is mutated when performing queries #8922
Comments
Hey @mikkelwf this is good detective work. As things are now, the It has been on the backburner for us to change how this works for a while now. I actually don't think we should have the Now might be the time to make this change. Thanks for bringing this up. 👍 |
Thanks! I've tested the search plugin and it works as expected now :) I still think you should consider changing the mutating aspect of the locale included inside re. But its probably a post 3.0 release thing to fix.. :) |
That was exactly our conclusion. |
This issue has been automatically locked. |
Describe the Bug
I'm trying to use the
beforeSync
transformer in the search plugin to alter collection data prior to saving it to search results.I use localized fields. When i want to utilize
req.locale
to see which data I need to change, the locale has been changed from the selected locale (en
orda
) toall
.It's because the syncWithSearch hook from the search plugin set the locale to
all
and this call also has thereq
object included in the config.payload/packages/plugin-search/src/Search/hooks/syncWithSearch.ts
Line 33 in 915a3ce
The problems is not only with search, as far as I can see all calls to the locale api that includes the
req
object, likeI can omit including the
req
, but then I opt out of transactions (AFAIK).Also mutating the
req
object seems strange, shouldn't this be kinda static?Link to the code that reproduces this issue
https://github.com/re-cph/payload/tree/bug/req_locale_mutation
Reproduction Steps
Run tests
Which area(s) are affected? (Select all that apply)
plugin: search, db-sqlite, area: core
Environment Info
Payload: 3.0.0-beta.120
Nodejs: 20.10.0
next: 15.0.1
The text was updated successfully, but these errors were encountered: