lanto03 / couchdb-python

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

ListFields can not be assigned to ListFields #14

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Assigning one ListField instance to another converts the data from a json
compatible list to an AnonymousStruct Schema instance. Repro:

class Post(Model):
     title = TextField()
     content = TextField()
     pubdate = DateTimeField(default=datetime.now)
     comments = ListField(DictField(Schema.build(
         author = TextField(),
         content = TextField(),
         time = DateTimeField()
     )))

post = Post(title='Foo bar')
post.comments.append(author='myself', content='Bla bla',
                      time=datetime.now())
print post.comments
post.comments = post.comments
print post.comments

You should see that the second print of post.comments is wrong. This
happens because ListField._to_json does not correctly convert a Proxy to
json data.

One possible solution is attached. Very small patch, but it sure took me a
while to figure out given the nested nature of DictField and ListField.

Original issue reported on code.google.com by schi...@gmail.com on 12 Jun 2008 at 1:11

Attachments:

GoogleCodeExporter commented 8 years ago
Patch applied in r74. Thanks!

Original comment by cmlenz on 26 Jun 2008 at 9:21