[Zope] Sessions and Persistence
Peter Bengtsson
peter at fry-it.com
Sun Nov 13 06:57:08 EST 2005
Dennis, can you try the same thing but without recreating SESSION as a
variable of REQUEST, i.e. like this instead::
# Script (Python) "setSessionVariable"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=var, val
##title=
##
request = container.REQUEST
RESPONSE = request.RESPONSE
session=request['SESSION']
session[var]=val
#request.set( 'SESSION', session )
That's how I always have been using it. Remember, type(REQUEST) !=
type({}) and the same applies for REQUEST.SESSION
On 11/12/05, Dennis Allison <allison at shasta.stanford.edu> wrote:
> Current configuration:
> Linux RH7.3
> Zope 2.8.4
> Python 2.4.2 (but the same is observed with Python 2.3.5)
>
> I continue to observe occasional failures of the Zope session variable
> mechanism. The problem manifests itself by a KeyError when accessing data
> in the session data container. We have recently moved to Zope 2.8.4 from
> Zope 2.7.6. The frequency of these errors aooears to have increased
> significantly; of late, we have occasionally seen error messages saying
> that an entire SESSION data container is missing.
>
> The session variable interface is very simple: a pair of Python Scripts,
> one that gets a session variable and another that sets it. Both use the
> copy-out/copy-in mechanism required for persistence.
>
> ## Script (Python) "getSessionVariable"
> ##bind container=container
> ##bind context=context
> ##bind namespace=
> ##bind script=script
> ##bind subpath=traverse_subpath
> ##parameters=varname
> ##title=
> ##
> request=container.REQUEST
> session=request['SESSION']
> return session[varname]
>
>
> # Script (Python) "setSessionVariable"
> ##bind container=container
> ##bind context=context
> ##bind namespace=
> ##bind script=script
> ##bind subpath=traverse_subpath
> ##parameters=var, val
> ##title=
> ##
> request = container.REQUEST
> RESPONSE = request.RESPONSE
> session=request['SESSION']
> session[var]=val
> request.set( 'SESSION', session )
>
> Most of the information we store in session variables are simple numbers
> or strings. In a few instances, we store python lists, python tuples, or
> python dictionaries.
>
> I am beginning to suspect the source of my bug is a persistence problem
> perhaps triggered by a conflict error or garbage collection in the
> temporary store used to hold the session variables.
>
> I further suspect that lists and dictionaries stored in session variables
> need to be instances of PersistentDict and PersistentList and not ordinary
> python data structures.
>
> I'd appreciate confirmation on these two issues from someone who knows the
> persistence mechanism better than I.
>
> Neither PersistentDict nor PersistentList are exposed in the restricted
> namespace. Advice as to how to expose them would be helpful as well.
>
> If I have a complex data structure (a list of dictionaries) does all the
> substructure need to have persistence wrappers as well--that is, does it
> have to be turtles all the way down?
>
> Thanks in advance. -d
>
> _______________________________________________
> Zope maillist - Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
>
--
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com
More information about the Zope
mailing list