A few weeks ago I had a problem caused by storing a rows object in session.
Anthony helped me solve the problem and provided me with the following
explanation:
When you store objects in the session, those objects have to be pickled
(i.e., serialized for storage). A DAL Row object is pickled as is, so when
you retrieve it from the session, it is still a Row object.
session.organization and session.address are both Row objects (because they
are just a single row), so they still work when you retrieve them from the
session.
However, session.telecom is a Rows object (i.e., multiple Row objects
combined). Rows objects cannot be pickled as is, so the DAL converts them
to a list of dictionaries using the Rows.as_list() method. So, when you
loop through the rows of session.telecom, each row is actually just a plain
Python dict, not a DAL Row. Therefore, you cannot reference fields using
the dot notation:
tel.telTypeID # doesn't work because tel is a dict
Instead, you have to use standard dict syntax:
tel['telTypeID'] # this should work fine
Another option is to convert session.telecom to a list of Row objects
(instead of allowing the DAL to convert it to a list of dicts). So, in
detail(), just do:
session.telecom=[row for row in db(db.Telecommunication.nodeID==session.id)\
.select(db.Telecommunication.ALL,orderby=db.Telecommunication.telTypeID)]
Then you can continue to use the dot notation (i.e., tel.telTypeID) in the
view.
In a mock application in web2py 1.99.7 I overlooked this solution and
implemented:
def generateContact():
...
session.telecom=db(db.Telecom.nodeID==session.id).select(db.Telecom.ALL,orderby=db.Telecom.telTypeID)
return None
def vcard():
...
return dict(...,telecom=session.telecom,...)
... and in the view:
...
{{for tel in telecom:}}
{{k=tel.telTypeID}}
{{v=tel.value}}
...
Some how this doesn't result in an error ticket, has anything changed?
Kind regards,
Annet