-
Notifications
You must be signed in to change notification settings - Fork 395
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
Avoid to cache form errors #568
Conversation
|
Interesting. What would be the API then? I can imagine two scenarios:
What do you think? I like this second scenario better. If this API seems OK to you, I will open another PR as I believe it is a different matter than this one. That way we can merge this one? |
Maybe just make the list of form errors an attribute called It's been a long time since I used form-level errors, maybe it's not actually needed. I'm trying to think of a scenario that I'd use them over just adding the error to a field. I don't think it was ever documented as a feature, so it's probably ok to change the behavior. If someone does report an issue, we can always address it in a bug fix. Given that piece of the documentation you removed that called out when it would be regenerated, I'm thinking form-level errors were just an accident. I'm still hesitant to remove caching, as users might access I guess overall I'm fine with the PR as-is, we can always address these things later if someone brings them up. |
I fixed your suggestions. About perfs
I cannot picture a real world case where the caching has significant performance impact:
Even in the worst case scenario, think that building the dict won't do a large difference. Say a Form containing 100 FormFields themselve 100 FormFields themselve containing 100 Fields, errors for each possible field. So this is about building a dict with 1M entries. Now let us say you access the dict 10 times, here are the profiling results on my computer: >>> profile.run('for _ in range(10): {x:x for x in range(10^6)}')
14 function calls in 0.000 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 :0(exec)
1 0.000 0.000 0.000 0.000 :0(setprofile)
10 0.000 0.000 0.000 0.000 <string>:1(<dictcomp>)
1 0.000 0.000 0.000 0.000 <string>:1(<module>)
1 0.000 0.000 0.000 0.000 profile:0(for _ in range(10): {x:x for x in range(10^6)})
0 0.000 0.000 profile:0(profiler) About form-level errorsI totally see cases where form-level errors would be pertinent. For instance when you have each individual field that has a correct value, but the whole form do not make sense. |
Looks good now. For your example, I'd add validation for each field that its value is after the previous field, so the error would go on the field that didn't validate. I guess it comes down to a matter of preference. Let's just merge this and leave it for now. |
I will also backport it in branch 2.2 |
Caching form errors may cause some strange behaviors when a form
errors
attribute is accessed during validation, and performance benefits are not obvious.This should fix #522