Skip to content

Conversation

@vkarpov15
Copy link
Collaborator

Summary

#13748 points out that accessing user.hobbies actually modifies the hobbies array if there's a getter on elements of the hobbies array. That is a problem. To fix that, I moved the logic for applying getters from SchemaArray.prototype.applyGetters(), which is also called when you access user.hobbies, and into the top-level applyGetters() function, which is only called by toObject() and toJSON().

As a side effect, in order to avoid breaking Schema UUID tests, we instead need to apply getters on index access. So user.hobbies[0] will fire getters on hobbies.0, but not modify hobbies. That's what the changes to types/array/index.js are for.

Still to investigate: it looks like oneUser.get('hobbies.0') double calls getters with this PR. Worth checking before merging.

Also need to think about whether to merge this in 7.5, or wait for 8.0. The types/array/index.js changes seem a bit too heavy for a patch release.

Examples

Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@vkarpov15 vkarpov15 added this to the 7.5 milestone Aug 28, 2023
@vkarpov15 vkarpov15 changed the base branch from master to 7.5 August 28, 2023 20:04
@vkarpov15 vkarpov15 merged commit c1d5b76 into 7.5 Aug 28, 2023
@AbdelrahmanHafez AbdelrahmanHafez deleted the vkarpov15/gh-13748 branch August 28, 2023 21:56
vkarpov15 added a commit that referenced this pull request Aug 29, 2023
fix(document): avoid double-calling array getters when using `.get('arr.0')`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants