Problem with SUM on DAL statement

80 views
Skip to first unread message

Jim S

unread,
Jul 21, 2013, 9:33:51 AM7/21/13
to web...@googlegroups.com
Just upgraded to latest trunk, Version 2.6.0-development+timestamp.2013.07.20.12.59.52.

Having a problem with SUM statements that previously worked.

If the query returns no rows, then I'm getting this traceback:

Traceback (most recent call last):
File "C:\dev\web2py\gluon\restricted.py", line 212, in restricted
exec ccode in environment
File "C:/dev/web2py/applications/ibc/controllers/dashboard.py", line 2035, in <module>
File "C:\dev\web2py\gluon\globals.py", line 193, in <lambda>
self._caller = lambda f: f()
File "C:/dev/web2py/applications/ibc/controllers/dashboard.py", line 1094, in contract_fees_ytd_by_distributor
(db.national_sales_data.Invoice_Print_Date__c<=to_date)).select(processing_fees_sum).first()[processing_fees_sum] or 0
File "C:\dev\web2py\gluon\dal.py", line 6888, in __getitem__
return ogetattr(self, key)
AttributeError: 'Row' object has no attribute 'SUM(national_sales_data.Processing_Fees__c)'
My code is:

processing_fees = db((db.national_sales_data.Invoice_Print_Date__c>=from_date) &
(db.national_sales_data.Trading_Partner_ID__c==trading_partner) &
(db.national_sales_data.Invoice_Print_Date__c<=to_date)).select(processing_fees_sum).first()[processing_fees_sum] or 0

Previously this would return 0 if there were no rows selected in the query.

-Jim

Niphlod

unread,
Jul 21, 2013, 9:48:29 AM7/21/13
to web...@googlegroups.com
this should have been fixed already on the latest trunk....

Jim Steil

unread,
Jul 21, 2013, 9:49:16 AM7/21/13
to web...@googlegroups.com
Do you have a test you can run on it?  None of mine are working and I just updated in the last hour.


--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/hgYEY3ZdSK4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Michele Comitini

unread,
Jul 21, 2013, 10:22:16 AM7/21/13
to web...@googlegroups.com
There is a bug. must be None i.e. the result is not defined.

I fixed the bug and I will send the PR asap

db.define_table('tt', Field('aa', 'integer'))

assert(db(db.tt.aa == 2).count()==0)
sum = (db.tt.aa + 1).sum()
assert(db(db.tt.aa == 2).select(sum).first()[sum]==0)
-> AssertionError

I added tests for travis too.


2013/7/21 Jim Steil <ato....@gmail.com>

--
 
---
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+un...@googlegroups.com.

Jim Steil

unread,
Jul 21, 2013, 10:48:46 AM7/21/13
to web...@googlegroups.com

Thanks.  Really appreciate the prompt reply on a Sunday morning!!

Jim

Michele Comitini

unread,
Jul 21, 2013, 10:57:14 AM7/21/13
to web...@googlegroups.com
Warm sunday afternoon here in Italy ;-)



2013/7/21 Jim Steil <ato....@gmail.com>

Jim Steil

unread,
Jul 21, 2013, 8:05:53 PM7/21/13
to web...@googlegroups.com
That fixed it.  Thanks again.  Enjoy the weather while you can.  Here in Wisconsin, the summer goes by too quickly.
Reply all
Reply to author
Forward
0 new messages