lanto03 / couchdb-python

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

Using Database.__setitem__ with JSON string bug #18

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
#test.py
import couchdb
server = couchdb.Server("http://localhost:5984")
db = server.create('test')
db['doc'] = '{ "foo": "bar" }'

#causes:
Traceback (most recent call last):
  File "test.py", line 4, in <module>
    db['doc'] = '{ "foo": "bar" }'
  File "build/bdist.linux-x86_64/egg/couchdb/client.py", line 264, in
__setitem__
AttributeError: 'str' object has no attribute 'update'

It would appear that Database.__setitem__ assumes that the passed document
is a dict object.

Attached a trivial patch.

Original issue reported on code.google.com by paul.jos...@gmail.com on 4 Jul 2008 at 1:18

Attachments:

GoogleCodeExporter commented 8 years ago
Why would it accept JSON strings? Do you have an actual use case for that?

Original comment by cmlenz on 21 Jul 2008 at 9:16

GoogleCodeExporter commented 8 years ago
Hmm. Totally can't remember the use case I had when working on this, but I would
totally expect it to accept JSON strings. I mean, Database.create() accepts 
JSON, why
wouldn't Database.__setitem__?

Original comment by paul.jos...@gmail.com on 21 Jul 2008 at 5:56

GoogleCodeExporter commented 8 years ago
Hmm, that Database.create() accepts a JSON string is merely a coincidence, 
definitely not by design :P

Original comment by cmlenz on 21 Jul 2008 at 9:18

GoogleCodeExporter commented 8 years ago
Seems to me that you should be able to cast / create anything as a string...

Original comment by wjh...@gmail.com on 14 Oct 2008 at 1:12

GoogleCodeExporter commented 8 years ago
I don't think this is a good idea. Python is a strongly typed language, and 
this library shouldn't be taking a string 
and implicitly decoding it to a dict behind the scenes.

Original comment by cmlenz on 5 Nov 2008 at 5:00