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