[Zope] Changes to dictionary disappear

Glen Ecklund Glen@TheGeoGroup.com
Tue, 06 May 2003 16:33:30 -0500


Hi.  I thought this was working, but now it has turned against me.
I'm losing the changes I make to a dictionary.
I have created a stand-alone script to demonstrate the problem:

------------------------------------------------------------

## Script (Python) "test3"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
testdict = {}

try:
    print 'AA1'
    dict_len = len(container.testdict)
    print 'AA2'
except:
    print 'Creating new testdict'
    try:
        print 'BB1'
        textdict = {}
        print 'BB2'
        container.manage_addProperty(id='testdict', value=testdict, \
                               type='dictionary', REQUEST=None)
        print 'BB3'
        dict_len = len(container.testdict)
        print 'BB4'
    except:
        raise

print 'len=', dict_len
print 'testdict=', container.testdict

container.testdict[dict_len] = dict_len
dict_len = len(container.testdict)

container.testdict[dict_len] = dict_len
dict_len = len(container.testdict)

print 'len=', dict_len
print 'testdict=', container.testdict

return printed
------------------------------------------------------------
When I run the script, sometimes it updates the dictionary properly (
adding two objects to the dictionary), but more often, it appears to
have added to the dictionary, but the changes are lost the next time
I run the script.  
So, just now it added to the dictionary once, increasing the starting
length from 0 to 2, but every time I run it since then the starting length
is always 2, so I get the same output, as follows:
------------------------------------------------------------
AA1
AA2
len= 2
testdict= {1: 1, 0: 0}
len= 4
testdict= {3: 3, 2: 2, 1: 1, 0: 0}
------------------------------------------------------------

-- 
Glen Ecklund
The Geo Group
6 Odana Court
Madison, WI 53719  USA

glen@TheGeoGroup.com
+1 608 230 1000