You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rails 6.1.1 broke the validating_enum code with the following commit (this appears to have been committed directly to main and there is no associated PR): rails/rails@3813021
Per the commit, this was in response to issue rails/rails#41118. In the issue the user is setting up an enum mapping a class constant to an integer. The above referenced commit changes the predicate convenience implementation to use the X_for_database method which will call serialize on the underlying EnumType. This is surprising to us because we expect serialize to only be called when the data is going to be sent to the DB. Our custom ValidateableEnumType type included a guard to raise a KeyError for invalid data in this case; a final business logic check prior to having the DB yell at us or worse silently do something unexpected (looking at you "invalid".to_i => nil).
We are not sure yet how best to approach updating this code for Rails 6.1. There's currently an open PR which looks to make this type of validation a first-class feature, maybe, in Rails 7: rails/rails#41730. But this is still pending as of the writing of this comment.
The text was updated successfully, but these errors were encountered:
Rails 6.1.1 broke the
validating_enum
code with the following commit (this appears to have been committed directly to main and there is no associated PR): rails/rails@3813021Per the commit, this was in response to issue rails/rails#41118. In the issue the user is setting up an enum mapping a class constant to an integer. The above referenced commit changes the predicate convenience implementation to use the
X_for_database
method which will callserialize
on the underlyingEnumType
. This is surprising to us because we expectserialize
to only be called when the data is going to be sent to the DB. Our customValidateableEnumType
type included a guard to raise aKeyError
for invalid data in this case; a final business logic check prior to having the DB yell at us or worse silently do something unexpected (looking at you"invalid".to_i => nil
).We are not sure yet how best to approach updating this code for Rails 6.1. There's currently an open PR which looks to make this type of validation a first-class feature, maybe, in Rails 7: rails/rails#41730. But this is still pending as of the writing of this comment.
The text was updated successfully, but these errors were encountered: