Uh oh...I just removed requires from the computed field and reran my unit 
tests, and now validate_and_insert inserts but the computed field isn't 
calculated at all! I tried insert and it does the computation.

Is there some reason validate_and_insert would not compute where insert 
does?


On Wednesday, April 19, 2017 at 7:27:45 PM UTC-4, Chris wrote:
>
> I looked it up:
>
> Notice that requires=... is enforced at the level of forms, required=True 
>> is enforced at the level of the DAL (insert), while notnull, unique and 
>> ondelete are enforced at the level of the database. While they sometimes 
>> may seem redundant, it is important to maintain the distinction when 
>> programming with the DAL.
>>
>
>  The mix of form, DAL and database level validation threw me off, but I 
> think I get it now. requires= would be checked before any DAL logic. I'll 
> remove the logic from the computed field. Hopefully it should be populated 
> for all future values. Thanks!
>
> On Tuesday, April 18, 2017 at 7:08:39 PM UTC-4, Anthony wrote:
>>
>> On Tuesday, April 18, 2017 at 5:41:38 PM UTC-4, Chris wrote:
>>>
>>> Thanks for the info Anthony! I'll try one of those approaches.
>>>
>>> Why is validation run before compute?
>>>
>>
>> In terms of implementation, compute is handled in the .insert() method, 
>> which must necessarily run after validation. I suppose we could add code to 
>> calculate computed values before validation in the .validate_and_ methods, 
>> but I don't think that really makes sense. Computed fields should not need 
>> to be validated, as they are in control of generating their own values. You 
>> should instead validate the inputs to the computed field.
>>
>> Anthony
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to