Skip to content

Conversation

pimpin
Copy link
Collaborator

@pimpin pimpin commented Jan 8, 2025

WHY ?

To fix a bug, having nester resource change reset on #save.

HOW ?

  • Add failing test to reproduce the unexpected behaviour
  • remove Active Model dirty since the reset was made by the super changes_applied provided by AR::Dirty

NB : in AR, the cast is done at assignment time. Lets try to do it.


TODO before undraft the PR :

  • check CI is green
  • Rework PR title and description

TODO before merge the PR :

pimpin added 6 commits January 6, 2025 15:33
NB : in AR, the cast is done at assignment time. Lets try to do it.
TODO : fix move casting stuff from serialize and place them in cast obviously
@pimpin pimpin changed the title Remove ActiveRecord::Dirty Remove ActiveRecord::Dirty usage Jan 8, 2025
And keep unchanged the serialize_value needed for queries (ie find_by_some_time)
@pimpin pimpin force-pushed the fix_save_return_for_nested branch from f4ae61b to 3d71024 Compare January 16, 2025 15:46
@pimpin pimpin requested a review from Copilot June 23, 2025 15:27
Copilot

This comment was marked as outdated.

pimpin and others added 3 commits June 24, 2025 17:34
- Remove double casting in create_setters to avoid type inconsistencies
- Fix Timestamp type precision by applying floor() during cast
- Fix DateTimeWith3Decimal precision handling in both cast and serialize

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@pimpin pimpin marked this pull request as ready for review August 25, 2025 15:56
@pimpin
Copy link
Collaborator Author

pimpin commented Aug 25, 2025

Thanks to Claude, we get a green inplem according to CI. Let's check in Docto CI that this implem is not breaking smth.

@pimpin pimpin requested a review from Copilot August 25, 2025 16:15
Copy link

@Copilot 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 removes ActiveRecord::Dirty usage to fix a bug where nested resource changes were being reset on save operations. The change replaces the ActiveRecord::Dirty dependency with a custom implementation to handle change tracking properly for nested resources.

  • Removes ActiveModel::Dirty inclusion and replaces with custom Changeable module
  • Modifies changes_applied method to prevent unwanted change resets
  • Adds test coverage for the nested resource change preservation bug

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/couchbase-orm/base.rb Removes ActiveModel::Dirty inclusion, keeping only custom Changeable module
lib/couchbase-orm/changeable.rb Removes call to super in changes_applied to prevent change resets
lib/couchbase-orm/types/timestamp.rb Adds .floor calls to timestamp casting for consistency
spec/type_spec.rb Adds cast method to DateTimeWith3Decimal test class
spec/type_nested_spec.rb Adds test cases to verify nested resource changes are preserved after save

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

Comment on lines +6 to +9
return Time.at(value).floor if value.is_a?(Integer) || value.is_a?(Float)
return Time.at(value.to_i).floor if value.is_a?(String) && value =~ /^[0-9]+$/
return value.utc.floor if value.is_a?(Time)
super(value).utc.floor
Copy link
Preview

Copilot AI Aug 25, 2025

Choose a reason for hiding this comment

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

The addition of .floor calls changes the behavior of timestamp casting by truncating subsecond precision. This could be a breaking change for consumers expecting microsecond precision in timestamps. Consider documenting this behavioral change or making it configurable.

Suggested change
return Time.at(value).floor if value.is_a?(Integer) || value.is_a?(Float)
return Time.at(value.to_i).floor if value.is_a?(String) && value =~ /^[0-9]+$/
return value.utc.floor if value.is_a?(Time)
super(value).utc.floor
return Time.at(value) if value.is_a?(Integer) || value.is_a?(Float)
return Time.at(value.to_i) if value.is_a?(String) && value =~ /^[0-9]+$/
return value.utc if value.is_a?(Time)
super(value).utc

Copilot uses AI. Check for mistakes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We had a look at the doc of Time#floor and we thought it was ok ... but we must double check it.

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