The ticket is opened on this bug already without any 
attention, https://github.com/web2py/web2py/issues/1735

2017 m. lapkritis 7 d., antradienis 15:34:07 UTC+2, DaneW rašė:
>
> I have upgraded from 2.14.6 to 2.15.4 (in PythonAnywhere using Python 2.7 
> and MySQL) and I now get AttributeError*: *'Expression' object has no 
> attribute 'tablename' whenever I use COUNT or SUM in a query for SQLTABLE.
>
> It looks as though the intermediate variable names for the SUM and COUNT 
> fields are not being found. SQLTABLE works fine for standard database 
> fields.
>
> A workaround seems to be to use grid=rows.as_list() rather than 
> grid=SQLTABLE(rows,headers=hdrs) and then build the table manually in the 
> view rather than just using {{=grid}} but this is extra work and I use 
> SQLTABLE quite a lot.
>
> Traceback *(*most recent call last*):*
>
>   File "/home/appgov/web2py/gluon/restricted.py"*, *line 219*, in *
> restricted
>
>     *exec(*ccode*, *environment*)*
>
>   File "/home/appgov/web2py/applications/apg/controllers/cg.py" 
> <https://www.appgov.org/admin/default/edit/apg/controllers/cg.py>*, *line 
> 836*, in <*module*>*
>
>   File "/home/appgov/web2py/gluon/globals.py"*, *line 414*, in <lambda>*
>
> *    self.*_caller *= lambda *f*: *f*()*
>
>   File "/home/appgov/web2py/applications/apg/controllers/cg.py" 
> <https://www.appgov.org/admin/default/edit/apg/controllers/cg.py>*, *line 
> 657*, in *cgsusearch
>
>     grid *= *SQLTABLE*(*rows*, *headers*=*hdrs*, *truncate*=*50*)*
>
>   File "/home/appgov/web2py/gluon/sqlhtml.py"*, *line 3330*, in *__init__
>
>     tablemap *= *dict*(((*f*.*tablename*, *f*.*table*) for *f *in *
> fieldmap*.*values*()))*
>
>   File "/home/appgov/web2py/gluon/sqlhtml.py"*, *line 3330*, in <*genexpr
> *>*
>
>     tablemap *= *dict*(((*f*.*tablename*, *f*.*table*) for *f *in *
> fieldmap*.*values*()))*
>
> AttributeError*: *'Expression' object has no attribute 'tablename'
>
>
> Code: 
>
>     query = db.dpspend.supplier.like(xsearch, case_sensitive=False)
>
>     isum = db.dpspend.amount.sum()
>
>     icount = db.dpspend.amount.count()
>
>     # group by family then supplier ....
>
>     rows = db(query).select(db.dpspend.dpfamily, db.dpspend.supplier, 
> isum, icount, orderby=db.dpspend.dpfamily, 
> groupby=db.dpspend.dpfamily|db.dpspend.supplier)
>
>     # Calculate the overall total values ....
>
>     for row in rows:
>
>         session.cgtotamt = session.cgtotamt + row._extra[isum]
>
>         session.cgtotrecs = session.cgtotrecs +  row._extra[icount]
>
>         session.cgtotsus += 1
>
>     db.dpspend.amount.represent  = lambda value, row: 
> DIV('{0:,}'.format(0.0 if value == None else value), _style='text-align: 
> right;')
>
>     hdrs = {'dpspend.dpfamily':T('Department'),
>
>             'dpspend.supplier':T('Supplier name'),
>
>             'SUM(dpspend.amount)':T('Total amount'),
>
>             'COUNT(dpspend.amount)':T('Records')}
>
>     grid = SQLTABLE(rows, headers=hdrs, truncate=50)
>
>     return dict(grid=grid)
>
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to