Virtual fields disapeared from select() results (v2.11.2)

97 views
Skip to first unread message

Donatas Burba

unread,
Jun 6, 2015, 4:23:59 PM6/6/15
to web...@googlegroups.com
Hello everybody. I am testing my products on web2py v2.11.2 base and have error. I want to ask is it new feature that virtual fields no more exist in Row after select? It means if I have Field.Virtual('x', ...) in my model, after doing db(db.tablename).select() I had this 'x' in results (with web2py v2.10.4), but now it is missing and my code, that depends on virtual field, just breaks.
And secondly, why aren't "funny" names not allowed in field names? In search forms I am using one serializeJSON library (for serializing form and making ajax call) so for multiselects I must use names like 'classes[]' in order it would be serialized as array. But this is minor problem for me, I have a workaround already.

Paolo Valleri

unread,
Jun 7, 2015, 2:12:37 PM6/7/15
to web...@googlegroups.com
Hi,
The following works
db=DAL('sqlite:memory')
db.define_table('tt', 
    Field('vv', 'integer'), 
    Field.Virtual('x', lambda row: row.tt.vv * 10))
db.tt.insert(vv='1')
print db(db.tt).select().first()
printing
<Row {'x': 10L, 'id': 1L, 'vv': 1L}>
We need more details to understand what is failing in your case. Can you post a failing example?

Paolo

Donatas Burba

unread,
Jun 8, 2015, 1:57:25 AM6/8/15
to web...@googlegroups.com
So I must take some more testing and if it fails, I will paste sample source.

Donatas Burba

unread,
Jun 8, 2015, 4:11:41 PM6/8/15
to web...@googlegroups.com
This is failing example:

db=DAL('sqlite:memory')

db.define_table('tt', 
    Field('vv', 'integer'), 
    Field.Virtual('x', lambda row: row.tt.vv * 10))
    
db.define_table('tt2', 
    Field('ttref', 'reference tt'),
    Field('vv2', 'integer'))

tt1 = db.tt.insert(vv='1')
tt2 = db.tt.insert(vv='3')
db.tt2.insert(ttref=tt1, vv2='3')
db.tt2.insert(ttref=tt2, vv2='4')
    
records = db(db.tt).select(
    db.tt.ALL, db.tt2.ALL,
    join=[db.tt2.on(db.tt2.ttref == db.tt.id)]
)
for r in records:
    print r

Result:

<Row {'tt2': {'ttref': 1L, 'id': 1L, 'vv2': 3L}, 'tt': {'id': 1L, 'vv': 1L}}>
<Row {'tt2': {'ttref': 2L, 'id': 2L, 'vv2': 4L}, 'tt': {'id': 2L, 'vv': 3L}}>

As you can see virtual field 'x' (in table 'tt') is missing. As I understand this occurs when selecting records from more than one table. In my case (with PostgreSQL) every time I use db(...).select(db.table.ALL, TOTAL_ROWS, ...) where TOTAL_ROWS = 'COUNT(*) OVER()'.

Paolo Valleri

unread,
Jun 9, 2015, 2:56:35 AM6/9/15
to web...@googlegroups.com
I see the problem now, thanks for pointing it out.
I'll post a fix later today.

 Paolo

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/l8V3nAzE4Hs/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/d/optout.

tim.n...@conted.ox.ac.uk

unread,
Jun 9, 2015, 4:44:59 AM6/9/15
to web...@googlegroups.com
Lovely!  I was just about to post this problem.

Paolo Valleri

unread,
Jun 9, 2015, 12:18:57 PM6/9/15
to web...@googlegroups.com

Donatas Burba

unread,
Jun 10, 2015, 12:39:47 PM6/10/15
to web...@googlegroups.com
Thank you. Will be waiting for stable release with this fix. Reverting to v2.10.4 for now.
Reply all
Reply to author
Forward
0 new messages