Fix broken populate traversal with no fragment #16109
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.
What does it do?
Actual fix here, the rest of the changes are tests added to check we don't have this regression in the future
Prevent recursion on undefined populate fragment values upon populate traversal (during query sanitization)
Why is it needed?
Null & undefined values for the populate fragment upon query traversal cause the traversal to throw due to an unexpected Object.entries operation on an undefined value.
How to test it?
Using the API integration tests:
yarn test:api packages/core/strapi/tests/api/sanitize/sanitize-query.test.api.js
Or by starting the getstarted app, creating a new restaurant entity from the content manager, then heading to the content API and trying to access this URL
http://localhost:1337/api/restaurants?populate[dz][populate]=*
It should return you the restaurant and the content of its dynamic zone populated (at the second level)
Related issue(s)/PR(s)
fix #16105