First, note that the following is not doing what you think it is:

 rows=db(query).select(db.task.person,, ...)

db.task.person is a Field object, and it's "name" attribute is just the 
string name of the field itself, so the above is equivalent to:

 rows=db(query).select(db.task.person, 'person', ...)

which makes the second argument redundant with the first. Also, when using 
a non-Field object as a positional argument to .select(), accessing field 
values in the resulting Row objects will require using the full 
"tablename.fieldname" format (looks like you figured that out, as your 
later code uses row.task.charge rather than row.charge -- the latter would 
work if you didn't have that in the select).

If you want the "name" of the person selected (presumably db.task.person is 
a reference to a db.person table), then you will need to do a join 
you could just fetch the references stored in the db.task.person field and 
later fetch the names via recursive selects 
but that approach is much less efficient if you are fetching multiple 

Anyway, regarding the main error, please show the full traceback as well as 
your table definition.

And as an aside, no need for the line continuation backslashes inside of 
parentheses (i.e., you can/should remove all of the ones in the code you 
have shown).


On Sunday, September 18, 2016 at 10:59:07 PM UTC-4, Peter wrote:
> I got the error above while trying to rewrite and tidy up some code that I 
> had working but didn't do everything I wanted.
> This is a lot neater but it doesn't work yet I think I am close!
> I have a person table and a task table where task.person is type 
> 'references person' 
> This is the code (not working and has never worked) so all I can say is I 
> know it's wrong... 
> def generate_inv_details():
>     session.inv_details = []
>     session.inv_total = 0
>     today =
>     query = db( (db.task.person.belongs( session.company_persons)\        ## 
> hard coded some ids in place of session.. but to no avail!
>               & (db.task.start_time <= today )\                           ## 
> this line worked ok in my earlier format so don't think its date related
>               & (db.task.charge_to == 'COMPANY' )\
>               & (db.task.task_status == 'BILLABLE')))
>     rows=db(query).select( db.task.person,\
>                  ,\                          ## 
> tried removing this (may have changed the error code) but still did not work  
>                            db.task.title,\
>                            db.task.start_time,\
>                            db.task.duration,\
>                            db.task.task_type,\
>                            db.task.task_status,\
>                            db.task.charge_to,\
>                            db.task.charge,\
>                            db.task.payment_status )
>     session.inv_details=rows
>     for row in session.inv_details:
>         session.inv_total += row.task.charge
> Is this totally off the wall and not even close?  
> Is there a problem with the format of the select statement? (which I 
> suspect is the issue)  or 
> Is there a glaring problem elsewhere?
> You will have to trust me when I say I have put hours of frustration and 
> reading into this and I only post here as a last resort!
> Many thanks for your consideration!
> Peter

- (Documentation)
- (Source code)
- (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 
For more options, visit

Reply via email to