Issue 210 in couchdb-python: Database.save() with a Python datetime.datetime value raises the wrong exception

22 views
Skip to first unread message

couchdb...@googlecode.com

unread,
Apr 12, 2012, 7:24:45 AM4/12/12
to couchdb...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 210 by lee.w...@gmail.com: Database.save() with a Python
datetime.datetime value raises the wrong exception
http://code.google.com/p/couchdb-python/issues/detail?id=210

What steps will reproduce the problem?

>> import datetime
>> import couchdb
>> couch = couchdb.Server()
>> db = couch.create('datetime_error')
>> data = {'the_time': datetime.datetime.now() }
>> db.save(data)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\dev\python27\lib\site-packages\couchdb\client.py", line 407, in
save
_, _, data = func(body=doc, **options)
File "C:\dev\python27\lib\site-packages\couchdb\http.py", line 399, in
post_json
status, headers, data = self.post(*a, **k)
File "C:\dev\python27\lib\site-packages\couchdb\http.py", line 381, in
post
**params)
File "C:\dev\python27\lib\site-packages\couchdb\http.py", line 419, in
_request
credentials=self.credentials)
File "C:\dev\python27\lib\site-packages\couchdb\http.py", line 239, in
request
resp = _try_request_with_retries(iter(self.retry_delays))
File "C:\dev\python27\lib\site-packages\couchdb\http.py", line 196, in
_try_request_with_retries
return _try_request()
File "C:\dev\python27\lib\site-packages\couchdb\http.py", line 222, in
_try_request
chunk = body.read(CHUNK_SIZE)
AttributeError: 'dict' object has no attribute 'read'


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

Expect the real error to be raised:

>>> import json
>>> json.dumps(data)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\dev\python27\lib\json\__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "C:\dev\python27\lib\json\encoder.py", line 201, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\dev\python27\lib\json\encoder.py", line 264, in iterencode
return _iterencode(o, 0)
File "C:\dev\python27\lib\json\encoder.py", line 178, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: datetime.datetime(2012, 4, 12, 21, 18, 42, 696000) is not JSON
serializable

Exception is swallowed in http.py request method which has the following:

try:
body = json.encode(body).encode('utf-8')
except TypeError, e:
pass


What version of the product are you using? On what operating system?
* Windows 7 Enterprise
* CouchDB 1.2.0
* couchdb-python 0.8

Please provide any additional information below.

Not sure if it affects other JSON implementation. I'm using the standard
python library version.

couchdb...@googlecode.com

unread,
Sep 21, 2012, 4:06:22 AM9/21/12
to couchdb...@googlegroups.com
Updates:
Status: Fixed

Comment #1 on issue 210 by djc.ochtman: Database.save() with a Python
datetime.datetime value raises the wrong exception
http://code.google.com/p/couchdb-python/issues/detail?id=210

It looks like this should be fixed by revision 2908fd72e112.

Reply all
Reply to author
Forward
0 new messages