Skip to content

Conversation

@mmrlivingstone
Copy link
Contributor

We've run into an issue when reloading a document which has had it's ID set to one that matches the value of an existing document.

Right now, when .reload is called in these circumstances, the data is pulled from the database, but the document does not update it's new_record value to false. This results in errors when trying to save, as Mongoid attempts to insert the document instead of updating the existing one.

It's easy to reproduce with something like the pseudo-code below (the new specs also show this)

doc1 = SomeDocument.create!

doc2 = SomeDocument.new(id: doc1.id)
doc2.save! # This will error

@mmrlivingstone mmrlivingstone requested a review from a team as a code owner September 9, 2025 14:41
@mmrlivingstone mmrlivingstone requested a review from jamis September 9, 2025 14:41
@jamis jamis changed the title Make Reload Properly Update new_record MONGOID-5895 Make Reload Properly Update new_record Sep 9, 2025
@jamis jamis added the bug Fixes a bug, with no new features or broken compatibility label Sep 9, 2025
@jamis jamis merged commit 08988f5 into mongodb:master Sep 9, 2025
63 checks passed
@jamis
Copy link
Contributor

jamis commented Sep 9, 2025

Thank you for the patch! 👍

@mmrlivingstone
Copy link
Contributor Author

More than happy to help. Thanks for making this a breeze!

Do you have a release cadence for new versions, or is it "when it's ready" schedule?

@jamis
Copy link
Contributor

jamis commented Sep 9, 2025

@mmrlivingstone there's no official cadence, just "when it's ready." That said, we recently updated our release infrastructure to make it simpler to cut new releases, and we're trying to release more regularly. I'm hopeful this'll see the light of day in a week, two at the outside.

jamis pushed a commit to jamis/mongoid that referenced this pull request Sep 15, 2025
* Ensure reload properly handles instances where we create a new document, but set the ID to an existing one

* Fix misplaced spec
jamis added a commit that referenced this pull request Sep 17, 2025
* Ensure reload properly handles instances where we create a new document, but set the ID to an existing one

* Fix misplaced spec

Co-authored-by: Matthew Livingstone <matthew.livingstone@clio.com>
@jamis
Copy link
Contributor

jamis commented Sep 18, 2025

@mmrlivingstone -- Mongoid 9.0.8 has been released with this fix. Thank you for the patch, and for your patience!

@mmrlivingstone
Copy link
Contributor Author

@jamis Thanks for the incredibly quick turn around on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes a bug, with no new features or broken compatibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants