Fix Type#cast to support Rails 8.0 bulk operations #469
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.
Important
To run tests on this PR, it is necessary to merge the following PRs first
Motivation / Background
This Pull Request has been created because Rails 8.0 introduced changes to how
Type#cast
is used during bulk operations (insert_all
,upsert_all
), causing enumerated attributes with symbol values to fail. The issue affects only bulk operations while regular attribute assignment continues to work correctly.Fixes #462
Detail
This Pull Request changes the
Type#cast
method in enumerize to handle values more intelligently for Rails 8.0 compatibility.Steps to reproduce
Expected behavior
Bulk operations (
insert_all
,upsert_all
) should work correctly with symbol enum values like:active
, just like regular attribute assignment does.Actual behavior
In Rails 8.0, bulk operations fail when using symbol enum values because the
Type#cast
method incorrectly delegates to@subtype.cast
first, which returnsnil
for symbols when the subtype is an integer type.System configuration
Rails version: 8.0
Ruby version: 3.1.6
Testing
Added comprehensive tests for:
Type#cast
behavior with symbols, strings, and integersinsert_all
with mixed value typesupsert_all
with different value formatsEnumerize::Value
objectsAll tests pass on Rails 7.0, 7.1, and 8.0.