-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache result of validation once outcome is done #411
Comments
Just realized that there already exists some caching, checking for It's just that if interaction fails during validation phase, Would something like this work?
==UPDATE== The above would not work, if validations are successful, but some errors happens during
This way if it validates successfully, the results won't be cached yet, allowing it to be set after execute. |
So it's valid and you get an outcome but then when you call valid again it's failing? |
@AaronLasseigne actually it is the opposite: only when validation fails, would calling |
For a test I used: class I < ActiveInteraction::Base
VALID = [false, true].cycle
validate do |interaction|
interaction.errors.add(:base, 'failed') if !VALID.next
end
def execute; end
end I was able to cache the result by changing def valid?(*)
if instance_variable_defined?(:@_interaction_valid)
return @_interaction_valid
end
valid = super
self.result = nil unless valid
valid
end This seems to have fixed the issue. |
@tfausak we let people modify the value of an input but it doesn't change the |
I don't remember why we do that. |
After thinking about this some I think it's a great idea. We should always cache the result and we shouldn't let people modify the inputs. That makes the whole process more immutable. I think this would probably require a major version bump though. We have a few other things that also need a major bump so maybe it's time. |
Makes sense. We'll have to make sure we don't mess up using interactions in forms if they're immutable. |
@lulalala I believe this will fix the issue you were having. Once It'll be part of the 4.0.0 release. |
I just met another bug, where I have a callback, and calling |
I decided to go ahead and release this as a bug fix in v3.6.2. |
This is just throwing some ideas.
Currently, if we call
outcome.valid?
, it would re-evaluate all the validations again.If one validation is not idempotent, for example checking if it is run on weekdays, it can results in inconsistency between outcome object and its
valid?
results. (Say we run it on Friday 23:59 and then the controller gets to check its validity on Saturday 00:01)Would it makes sense to provide some caching mechanism, so that once outcome is done, outcome's error result can be cached, so that validations won't be run again?
The text was updated successfully, but these errors were encountered: