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
This is because validate itself is implemented as a callback (source). This is a problem for ActiveInteraction because we use validate to validate inputs (source). @nilcolor discovered this in #195.
As far as I can tell, the only reliable way to get our validation to happen where we want it is to override run_validations!. (You can see from the source that it doesn't provide a block to run_callbacks. That means around callbacks are executed around nothing.) I'm a little hesitant to do this because we can't call super; it would end up running the callbacks twice.
This is particularly frustrating because the documentation for validate suggests there's a validate instance method we could override. The link leads back to itself, but I think it's talking about this one.
The text was updated successfully, but these errors were encountered:
@AaronLasseigne and I talked this over in person. The problem with overriding run_validations! is that any validations would be run before validating inputs. So that's a non-starter.
One way out of this would be to introduce the validation callback, which is separate from the validate callback. Our input validation would be part of validate, and any user-defined validation should be part of validation. Even though this is what ActiveRecord does, I'm not a fan; the difference between validation and validate is too subtle and easy to mess up.
Another way out of this is to add a third callback for type checking. It would happen before validation. The callback flow would look like this:
:type_check
:validate
:execute
It might make sense to prevent validation if type checking fails.
Validation callbacks don't happen when I expect them to. Consider the following interaction.
I would expect the validation callbacks to be executed around the
validate
block. But that's not what happens. This is what that interaction outputs.This is because
validate
itself is implemented as a callback (source). This is a problem for ActiveInteraction because we usevalidate
to validate inputs (source). @nilcolor discovered this in #195.As far as I can tell, the only reliable way to get our validation to happen where we want it is to override
run_validations!
. (You can see from the source that it doesn't provide a block torun_callbacks
. That means around callbacks are executed around nothing.) I'm a little hesitant to do this because we can't callsuper
; it would end up running the callbacks twice.This is particularly frustrating because the documentation for
validate
suggests there's avalidate
instance method we could override. The link leads back to itself, but I think it's talking about this one.The text was updated successfully, but these errors were encountered: