I don't have a direct solution, but FYI I added this info to a bug
report on a related topic. http://code.google.com/p/web2py/issues/detail?id=374

Thanks for pointing out the problem.

On Aug 14, 8:57 am, Santiago Gilabert <[email protected]>
wrote:
> anyone?
>
> I found that someone else asked about the same issue 5 month ago but there
> are no comments about it.
>
> http://groups.google.com/group/web2py/browse_thread/thread/845e6cdef5...
>
> Thanks
> Santiago
>
> On Sat, Aug 13, 2011 at 7:07 PM, Santiago <[email protected]>wrote:
>
>
>
>
>
>
>
> > Hello,
>
> > I have the following definitions in db.py
>
> > class ElectionVirtualField(object):
> >  ...
> >  def is_presidential(self):
> >    def lazy(self=self):
> >      return self.election.category == 'P'
> >    return lazy
> >  ...
>
> > db.define_table('election',
> >  ...
> >  Field('category', length=1, label=T('Category')
> >  ...
>
> > The problem I have is that when I add a bunch of elections in dict()
> > (key = election.id, value = election row) and then traverse the dict,
> > I get wrong values from is_presidential()
>
> > Example:
>
> >    elections = dict()
> >    for election in db(db.election).select():
> >       elections[election.id] = election
>
> >    for (k, v) in elections.items():
> >      print k , ' ', v.category, ' ', v.is_presidential()
>
> >    Output:
> >    81   D   True
> >    79   P   True
>
> > As you can see, it returns True for both, but for the first one, it
> > should return False.
>
> > If I change the code to reload the election from the database, the
> > output is different:
>
> > Example:
>
> >    elections = dict()
> >    for election in db(db.election).select():
> >       elections[election.id] = election
>
> >    for (k, v) in elections.items():
> >      reloaded_election = db.election(k)
> >      print k , ' ', v.category, ' ', v.is_presidential()
>
> >    Output:
>
> >    81   D   False
> >    79   P   True
>
> > Does this mean that we can't save rows from DB on Build in types ?
>
> > Thanks in advance,
> > Santiago

Reply via email to