Skip to content

Commit e582ffe

Browse files
committed
DictField instances shouldn't be backed by the same dict (issue 101).
1 parent 63a69fc commit e582ffe

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

ChangeLog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ http://couchdb-python.googlecode.com/hg/?r=default
1010
* Added a `stats()` method to the `client.Server` class.
1111
* Added a `tasks()` method to the `client.Server` class.
1212
* Allow slashes in path components passed to the uri function (issue 96).
13+
* `DictField`s now have their own backing dictionary for each instance
14+
of their `schema.Document` (issue 101).
1315

1416

1517
Version 0.6

couchdb/schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,8 @@ class DictField(Field):
567567
>>> del server['python-tests']
568568
"""
569569
def __init__(self, schema=None, name=None, default=None):
570-
Field.__init__(self, name=name, default=default or {})
570+
default = default or {}
571+
Field.__init__(self, name=name, default=lambda: default.copy())
571572
self.schema = schema
572573

573574
def _to_python(self, value):

couchdb/tests/schema.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ def tearDown(self):
3131
except client.ResourceNotFound:
3232
pass
3333

34+
def test_mutable_fields(self):
35+
class Test(schema.Document):
36+
d = schema.DictField()
37+
a = Test()
38+
b = Test()
39+
a.d['x'] = True
40+
self.assertTrue(a.d.get('x'))
41+
self.assertFalse(b.d.get('x'))
42+
3443
def test_automatic_id(self):
3544
class Post(schema.Document):
3645
title = schema.TextField()

0 commit comments

Comments
 (0)