Skip to content

Conversation

@jamis
Copy link
Contributor

@jamis jamis commented Sep 29, 2025

Backport #6042 to 9.0-stable.

…ges (mongodb#6042)

* handle BSON::Decimal128 specially when checking for changes

* Reference the correct option in the context name

Co-authored-by: Copilot <[email protected]>

* Apparently #to_d is a recent addition to ruby-bson

---------

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings September 29, 2025 14:15
@jamis jamis requested a review from a team as a code owner September 29, 2025 14:15
@jamis jamis added the bug Fixes a bug, with no new features or broken compatibility label Sep 29, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR backports a fix from version 6042 to handle BSON::Decimal128 specially when checking for attribute changes in Mongoid. The issue occurs when map_big_decimal_to_decimal128 is enabled, where identical numeric values are incorrectly marked as changed due to incompatible equality comparison between BSON::Decimal128 and BigDecimal types.

  • Replaces direct attribute equality comparison with a new method that normalizes values before comparison
  • Adds helper methods to convert BSON::Decimal128 to BigDecimal for proper equality checking
  • Includes test coverage for the decimal128 scenario when the configuration option is enabled

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/mongoid/attributes.rb Implements normalized value comparison logic and helper methods to handle BSON::Decimal128 equality
spec/mongoid/attributes_spec.rb Adds test case to verify documents aren't marked as changed when writing identical decimal values

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@jamis jamis merged commit 7b05e2a into mongodb:9.0-stable Sep 29, 2025
62 checks passed
@jamis jamis deleted the 5890-backport-9.0 branch September 29, 2025 14:55
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