[Zope] Python script: problem with session
David Burton
eloquence@eloquent-designs.f2s.com
Wed, 12 Jun 2002 15:41:25 +0100
It also depends what is in the mapping.
The copy function is a shallow copy function, so a new dictionary is created, but if objects or arrays are stored within the dictionary, these will still be
references back to the same objects, and you will still have problems.
You could either try cloning these objects, avoiding modifying references to those objects, or look up information regard deep copying in the Python
documentation you've got available to you.
It's not something that I've had to work around, but something I have seen noted as a 'gotcha', so I'll have to leave it to someone else to suggest exact
methods for deep copying of objects within Zope.
HTH,
David Burton
12/06/2002 15:19:43, "p.t." <p.training@tin.it> wrote:
>Fine, Chris.
>I'll try your suggestion exactley in the way you wraite it down.
>I've already tryied this:
>
>context.REQUEST['foo'] = context.REQUEST.SESSION['foo'].copy()
>
>but (suprisingly) not working (and no error issue).
>Things work fine "renaming" objects, like:
>
>Initialise:
>context.REQUEST.SESSION['FOO'] = foo
>
>Assign:
>context.REQUEST['foo'] = context.REQUEST.SESSION['FOO']
>
>but this is quite impratical, because I'm often using indirect naming via
>the Zope function getitem().
>Thanks,
> p.t.
>
>At 10:01 12/06/2002 -0400, Chris McDonough wrote:
>>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 )
>> >
>> >
>>
>>
>>
>>_______________________________________________
>>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 )
>
>
>
>_______________________________________________
>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 )
>
"Into the abyss we stare, hoping that the abyss does not gaze so intently upon us"