Skip to content
  • Sean Griffin's avatar
    f888fad4
    Ensure numericality validations work with mutation · f888fad4
    Sean Griffin authored
    The detection of in-place changes caused a weird unexpected issue with
    numericality validations. That validator (out of necessity) works on the
    `_before_type_cast` version of the attribute, since on an `:integer`
    type column, a non-numeric string would type cast to 0.
    
    However, strings are mutable, and we changed strings to ensure that the
    post type cast version of the attribute was a different instance than
    the before type cast version (so the mutation detection can work
    properly).
    
    Even though strings are the only mutable type for which a numericality
    validation makes sense, special casing strings would feel like a strange
    change to make here. Instead, we can make the assumption that for all
    mutable types, we should work on the post-type-cast version of the
    attribute, since all cases which would return 0 for non-numeric strings
    are immutable.
    
    Fixes #17852
    f888fad4
    Ensure numericality validations work with mutation
    Sean Griffin authored
    The detection of in-place changes caused a weird unexpected issue with
    numericality validations. That validator (out of necessity) works on the
    `_before_type_cast` version of the attribute, since on an `:integer`
    type column, a non-numeric string would type cast to 0.
    
    However, strings are mutable, and we changed strings to ensure that the
    post type cast version of the attribute was a different instance than
    the before type cast version (so the mutation detection can work
    properly).
    
    Even though strings are the only mutable type for which a numericality
    validation makes sense, special casing strings would feel like a strange
    change to make here. Instead, we can make the assumption that for all
    mutable types, we should work on the post-type-cast version of the
    attribute, since all cases which would return 0 for non-numeric strings
    are immutable.
    
    Fixes #17852
Loading