Skip to content

Conversation

@AbdelrahmanHafez
Copy link
Collaborator

Will be testing other array methods soon, and fix any broken ones.

@vkarpov15 I am curious, what are the exact changes that introduced this bug?

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

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

Thanks @AbdelrahmanHafez . I think this was always a bug, map() and slice() create a new instance of Mongoose's custom document array class. It's just that in #8265 we started relying on arrayParentSymbol when doing operations like push() and splice() to ensure that populated() stays in sync.

I've thought about it some more and I think the way to go is to just add a check in _updateParentPopulated() that does an early return if parent == null. If you do docArr.map(), you get back a new array that shouldn't be tied to the Mongoose document. So I'd remove the custom map() implementation in favor of just skipping _updateParentPopulated() if the array doesn't have a parent.

@AbdelrahmanHafez
Copy link
Collaborator Author

AbdelrahmanHafez commented Nov 18, 2019

Thank you @Fonger

@vkarpov15
To understand correctly, what you're saying is map() and push() always had this bug? Because if that's the case, I've been using the combination and the test only started to fail lately.

You're right though, it makes more sense to return a good old JS array on mapping. Changes coming your way.

@AbdelrahmanHafez
Copy link
Collaborator Author

Got some failing tests on Node 4 and 5, will check them soon.

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

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

Thanks! This should also fix #8312

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.

2 participants