couchdbkit icon indicating copy to clipboard operation
couchdbkit copied to clipboard

View are not view but string

Open bussiere opened this issue 13 years ago • 4 comments

emailcouchs = Email.view('email/all') print emailcouchs print emailcouchs.count()

so it give me this error : <couchdbkit.client.ViewResults object at 0x1d68110> Traceback (most recent call last): File "saveemailpa.py", line 67, in print emailcouchs.count() File "/usr/local/lib/python2.7/dist-packages/couchdbkit/client.py", line 973, in count self._fetch_if_needed() File "/usr/local/lib/python2.7/dist-packages/couchdbkit/client.py", line 1004, in _fetch_if_needed self.fetch() File "/usr/local/lib/python2.7/dist-packages/couchdbkit/client.py", line 987, in fetch self._total_rows = self._result_cache.get('total_rows') AttributeError: 'str' object has no attribute 'get'

the latest with pip version with

and with your instruction :

Traceback (most recent call last): File "/home/bussiere/saveemail/testcouchdb.py", line 13, in emailcouchs = Email.view('email/all') File "/usr/local/lib/python2.7/dist-packages/couchdbkit/schema/base.py", line 585, in view db = cls.get_db() File "/usr/local/lib/python2.7/dist-packages/couchdbkit/schema/base.py", line 422, in get_db raise TypeError("doc database required to save document") TypeError: doc database required to save document [Finished in 0.6s]

Regards and thanks. Bussiere

bussiere avatar Aug 25 '12 16:08 bussiere

do you have any simple test that could help me to reproduce? That could help a lot :)

benoitc avatar Feb 09 '13 20:02 benoitc

I had a similar error in 0.6.4.

  File "/usr/local/lib/python2.7/dist-packages/couchdbkit-0.6.4-py2.7.egg/couchdbkit/client.py", line 943, in iterator
    self._fetch_if_needed()

  File "/usr/local/lib/python2.7/dist-packages/couchdbkit-0.6.4-py2.7.egg/couchdbkit/client.py", line 1019, in _fetch_if_needed
    self.fetch()

  File "/usr/local/lib/python2.7/dist-packages/couchdbkit-0.6.4-py2.7.egg/couchdbkit/client.py", line 1002, in fetch
    self._total_rows = self._result_cache.get('total_rows')

AttributeError: 'str' object has no attribute 'get'

When looking at the line of the exception, you see that

  • self._result_cache is expected to be a dict
  • the value is set in the previous line
        self._result_cache = self.fetch_raw().json_body
        self._total_rows = self._result_cache.get('total_rows')
        self._offset = self._result_cache.get('offset', 0)

So it looks like an invalid response was received from CouchDB. Maybe this should be checked in assigning _result_cache?

stefankoegl avatar Jul 24 '13 15:07 stefankoegl

In the cases I observed, the response from CouchDB was actually invalid. In all cases, the response was like

{ "total_rows":625838,"offset":323983,"rows":[
{"id":"938aa209c352e00a4d841be90352c472","key":"somekey","value":null,"doc":{ thedoc }},
{ many more results }

without the closing ]}.

stefankoegl avatar Aug 17 '13 20:08 stefankoegl

I could now track it down to https://issues.apache.org/jira/browse/COUCHDB-1769. Couch starts sending a view response, hits a duplicate and terminates the response. This produces the invalid JSON described above. So in my opinion this is a Couch bug, and not related to couchdbkit.

stefankoegl avatar Aug 17 '13 21:08 stefankoegl