[Zope] Python script: problem with session

Chris McDonough chrism@ZOPE.COM
Wed, 12 Jun 2002 10:01:48 -0400


I see... when you hold a reference to a dictionary in two places you
are holding a reference to the same object, therefore changes made
via one reference are reflected when you take a look at the object
via the other reference.

One way to avoid this in your case in a Python Script:

d = context.REQUEST.SESSION['foo']
REQUEST['foo'] = d.copy()

In other words, don't assign the value of SESSION['foo'] to
REQUEST['foo'], rather assign a copy.

----- Original Message -----
From: "p.t." <p.training@tin.it>
To: "Chris McDonough" <chrism@zope.com>
Cc: <zope@zope.org>
Sent: Wednesday, June 12, 2002 9:41 AM
Subject: Re: [Zope] Python script: problem with session


> Chris,
> it is a mapped object (a dictionary).
> A closer view is:
>
> First (in a calling procedure) I put in
> SESSION[processID]['status']['dataTable'] the name of a table.
> Then (in the called procedure) I retrieve this name to the current
status:
> REQUEST['status'] = SESSION[processID]['status']
>
> REQUEST['status'] can change some values before calling back the
caller.
> TIA,
>          p.t.
>
> At 09:10 12/06/2002 -0400, Chris McDonough wrote:
> >What kind of object does REQUEST['foo'] return?
> >
> >On Wed, 2002-06-12 at 08:43, p.t. wrote:
> > > I did already post this with a different thread: probably the
formulation
> > > was to complex. Or may be there is some very basic knowledge
I'm missing.
> > > I'll try again.
> > >
> > > If I assign to variable in a Python script (say
context.REQUEST['foo']) a
> > > value stored in SESSION (say context.SESSION['foo']), and then
I change
> > the
> > > retrieved value (the one in REQUEST, not the original one),
also the
> > > variable in SESSION is changed. In this way I have lost my
original
> > > information stored in SESSION!
> > >
> > > I've tryied to avoid this, but I can't manage to find how.
> > > Any suggestion?
> > >
> > > TIA,
> > >       p.t.
> > >
> > >
> > >
> > > _______________________________________________
> > > Zope maillist  -  Zope@zope.org
> > > http://lists.zope.org/mailman/listinfo/zope
> > > **   No cross posts or HTML encoding!  **
> > > (Related lists -
> > >  http://lists.zope.org/mailman/listinfo/zope-announce
> > >  http://lists.zope.org/mailman/listinfo/zope-dev )
>
>