lanto03 / couchdb-python

Automatically exported from code.google.com/p/couchdb-python
Other
0 stars 0 forks source link

DictFields share the same default dict #101

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.

>>> import couchdb
>>> from couchdb.schema import *
>>> class Test(Document):
...  a = DictField()
... 
>>> a = Test()
>>> b = Test()
>>> a
<Test None@None {'a': {}}>
>>> b
<Test None@None {'a': {}}>
>>> a.a["test"] = 10
>>> a
<Test None@None {'a': {'test': 10}}>
>>> b
<Test None@None {'a': {'test': 10}}>

2. You can now see that the two objects a and b now share the same dict a. Thus 
the default 
value for the DictField is shared between all documents of class Test. 
3.

What is the expected output? What do you see instead?

That the default dict for DictFields are not shared between different instances 
of the DictField

What version of the product are you using? On what operating system?

Bug is in both 0.6 and trunk. Tested on Mac OS X 10.6

Please provide any additional information below.

The only way to get around this bug right now is to override the dict value 
when creating new 
objects such as:

a = Test()
a.a = dict()

or 

a = Test(a=dict())

Original issue reported on code.google.com by dbrat...@gmail.com on 25 Nov 2009 at 10:22

GoogleCodeExporter commented 8 years ago
Should be fixed in r444b3d08d1. FWIW, I couldn't reliably get similar oddities 
using
a ListField (but I also didn't try very hard).

Original comment by djc.ochtman on 10 Dec 2009 at 3:57

GoogleCodeExporter commented 8 years ago
I can confirm that ListField does have the same issue.

Original comment by ru.w31...@gmail.com on 14 Dec 2009 at 12:24

GoogleCodeExporter commented 8 years ago
Do you have a concise test case?

Original comment by djc.ochtman on 14 Dec 2009 at 12:24

GoogleCodeExporter commented 8 years ago
Should I open a new issue for the ListField case or you reopen this one instead?

Original comment by ru.w31...@gmail.com on 14 Dec 2009 at 12:27

GoogleCodeExporter commented 8 years ago
Open a new issue, please.

Original comment by djc.ochtman on 14 Dec 2009 at 12:27