On Saturday, October 22, 2011 7:47:08 AM UTC-4, apple wrote:
>
> I am summing some data using the DAL: 
>       cash_price = db.orderline.cash_price.sum() 
>       lines = db(db.orderline.order_ == id).select(cash_price).first() 
>
> However if there are no lines then lines[cash_price] is "None". So I 
> added: 
>        lines[cash_price]=lines[cash_price] or 0

But this does not work either. You have to do: 
>        lines[cash_price]=lines._extra[cash_price] or 0 
>
> This is OK as it works. But wouldn't it be better if the sum were "0" 
> in the first place? Or if there is some logical reason for it to 
> "None" then one should to be able to say: 
>        lines[cash_price]=lines[cash_price] or 0
>

I don't think you necessarily want it to default to 0 whenever no records 
are found, as you might want to distinguish between that case (None) and 
when there are records but the sum is truly 0. However, it would be nice if 
the assignment above worked without needing to refer to _extra.

Anthony
 

Reply via email to