Skip to content

Check if $primaryKey is present before execute unset #2599

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

Merged
merged 2 commits into from
Sep 6, 2023

Conversation

FormigTeen
Copy link
Contributor

Fix: Exception on Dissociate Operation for Embed Models in MongoDB

Problem:

Previously, while executing a dissociate operation on Embed Models in MongoDB, an Exception was thrown that prevented the removal of Models. This happened specifically when a Model in the list lacked a $propertyKey.

Solution:

This Pull Request adds a validation check to the dissociate operation for Embed Models in MongoDB. With this fix, the application will now verify if a propertyKey is present in each Model in the list before proceeding with the removal. This resolves the issue of an Exception being thrown during the operation.

Testing

The fix has been thoroughly tested to ensure that the Exception no longer occurs. Now, a model will be successfully dissociated even if another model in the list lacks the $propertyKey.

@FormigTeen FormigTeen changed the title Check if $primaryKey is present before execute the unset Check if $primaryKey is present before execute unset Sep 5, 2023
@GromNaN
Copy link
Member

GromNaN commented Sep 5, 2023

Hello @FormigTeen, thank you for the detailed description and the patch. Could you add a non-regression test? The User class embeds Address model, it should be possible to write a scenario in EmbeddedRelationsTest to cover the bug.

@GromNaN GromNaN added bug relations Relations between documents labels Sep 5, 2023
@FormigTeen
Copy link
Contributor Author

Done @GromNaN , Thanks, I closed the other request but if you want I can open it by sending only the test case

@GromNaN GromNaN merged commit 035d704 into mongodb:master Sep 6, 2023
@GromNaN
Copy link
Member

GromNaN commented Sep 6, 2023

Thank you @FormigTeen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug relations Relations between documents
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants