Hello,

 I am new to web2py, and this group. I was conversing on IRC and it
was suggested by dingding1 that I should post this here.

I think there's a bug with virtualfields. It seems that if I try to
use a select() statement with only one field name, then virtualfields
will fail to work as it cannot find the other dependent fields it
needs to calculate the desired output.

So if this is desired behavior, it is not mentioned in the book (3rd
ed), and it seems to be counter intuitve as it seems like the
virtualclass should have access to all elements regardless of the
select query being run on it.

see following example code http://pastie.textmate.org/1308330

class MyVirtualFields(object):
    def production_total(self):
        return
self.production.production_shift_1+self.production.production_shift_2+self.production.production_shift_3
    def production_net(self):
        return
self.production.production_shift_1+self.production.production_shift_2+self.production.production_shift_3-
self.production.production_rejection
    def lid_total(self):
        return
self.production.lid_shift_1+self.production.lid_shift_2+self.production.lid_shift_3
#NOTE virtual fields cause a problem with SELCT() statements. In the
select statement if you don't include the required fields for the
calculation, it will give an error! This is a bug!
#crashes on the following query
#    rows = db(db.production.date_id ==
date.today()).select(db.production.delivered)
#if i comment our the select criteria as shown below, then it works
fine
#    rows = db(db.production.date_id ==
date.today()).select()#db.production.delivered)
db.production.virtualfields.append(MyVirtualFields())

is this a valid, or just flawed understanding on my part?
maybe it makes sense to not have virtualfields access to all fields,
because that would mean fetching all data from server all the time,
thereby slowing down.
but then it should allow a switch for disabling it's evaluation or
something so that when running code that doesn't require the
virtualfield then it can skip the evaluation.

Thank you for your patience.

Vijay

Reply via email to