Fix Time.new keyword arguments on JRuby 10#443
Merged
joshuacronemeyer merged 3 commits intoApr 12, 2026
Merged
Conversation
Replace `ruby2_keywords` approach with explicit `**kwargs` in `new_with_mock_time`. On JRuby 10 (Ruby 3.4 compat), the `ruby2_keywords` flag doesn't properly forward keyword arguments through `new_without_mock_time`, causing `TypeError: no implicit conversion of Hash into Integer` when ActiveModel deserializes datetime columns. The fix uses explicit `**kwargs` which works correctly across all Ruby versions and implementations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* master: Fix time-only DateTime.parse under freeze (travisjeffery#440) Improve and fix CI (travisjeffery#439)
Collaborator
|
Hi @johnnyshields! Thank you for this thoughtful contribution. I'd love to get this merged. Just a couple tweaks to the tests would help. Regarding test_time_new_with_keyword_arguments rescue ArgumentError doesn't catch TypeError, which is what older Ruby raises when a hash gets passed as the UTC offset positional argument. So maybe that test needs a conditional so it doesn't run for rubies that don't do keyword arguments Also, the elsif kwargs.any? branch covers Time.new(in: "+05:00") (kwargs only, no positional args) but there's no test for that specific case. Not a blocker, but worth adding for completeness. Holding our next release: #444 for this PR |
… a TypeError (or any other error) on older Ruby won't silently mask a failure. Also new test covering kwargs only, no positional args), which exercises the args.empty? && kwargs.any? branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ruby2_keywordsapproach with explicit**kwargsinnew_with_mock_timeruby2_keywordsdoesn't properly forward keyword arguments throughnew_without_mock_time, causingTypeError: no implicit conversion of Hash into IntegerTime.newwith keyword arguments internallyReproduction
Any Rails 7.2+ app on JRuby 10 that has timecop loaded and reads a datetime column:
Fix
Use explicit
**kwargsinstead ofruby2_keywords. This works correctly across all Ruby versions and implementations:Test plan
Time.newwithin:keyword argument (Ruby 3.1+)Time.newwith positional arguments (regression check)🤖 Generated with Claude Code