-
-
Notifications
You must be signed in to change notification settings - Fork 4k
fix(utils): prevent translation crash on primitive arrays #14565
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
base: develop
Are you sure you want to change the base?
fix(utils): prevent translation crash on primitive arrays #14565
Conversation
🦋 Changeset detectedLatest commit: fa7ff37 The changes in this PR will be included in the next version bump. This PR includes changesets to release 76 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Someone is attempting to deploy a commit to the medusajs Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
d7bdf45 to
fa7ff37
Compare
Summary
What — What changes are introduced in this PR?
This PR updates the canApplyTranslationTo function within the applyTranslations utility to strictly check if an item is an object before attempting to access its id property.
Why — Why are these changes relevant or necessary?
Currently, the translation utility iterates over all arrays found in an entity. If an entity has a JSONB column containing an array of primitive values (e.g., documents: ["/path/1.pdf", "/path/2.pdf"]), the utility attempts to treat these strings as entities. This causes a server crash (TypeError: Cannot use 'in' operator to search for 'id' in ...) because the code tries to check "id" in string.
How — How have these changes been implemented?
I added an isObject check to the canApplyTranslationTo function in packages/utils/src/translations/apply-translations.ts. The function now returns false for primitive values, preventing the recursion logic from crashing on simple arrays.
Testing — How have these changes been tested, or how can the reviewer test the feature?
I have added a regression test in packages/utils/src/translations/tests/apply-translations.spec.ts. The test:
Examples
Checklist
Please ensure the following before requesting a review:
yarn changesetand follow the promptsAdditional Context
This issue was discovered when using a custom Business entity with a documents JSONB column populated with file path strings. The crash only occurs when the ?locale= query parameter is present.
Note
Improves robustness of
apply-translationsto avoid crashes on arrays of primitives.isObjectguards incanApplyTranslationToandgatherIdsto skip non-objects before accessingidapply-translations.spec.tswith a regression case for arrays of strings@medusajs/utilsWritten by Cursor Bugbot for commit fa7ff37. This will update automatically on new commits. Configure here.