Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 211 by christop...@gmail.com: Cannot access _id and _doc
attributes in a view written in Python
http://code.google.com/p/couchdb-python/issues/detail?id=211
What steps will reproduce the problem?
- Create a view like this:
mapfunc="""
def foo(doc):
yield(doc._id, 42)
"""
- Create a query object like:
q=some_database.query(map_fun=mapfunc)
- The query object gets created properly:
<ViewResults <TemporaryView 'def foo(doc):\n yield(doc._id,42)\n'
None> {}>
- However getting the rows or the number of rows fails:
/home/chaas/projekte/debshots/<ipython-input-82-f16a381fffa4> in <module>()
----> 1 q.total_rows
/usr/lib/pymodules/python2.7/couchdb/client.pyc in total_rows(self)
1013 """
1014 if self._rows is None:
-> 1015 self._fetch()
1016 return self._total_rows
1017
/usr/lib/pymodules/python2.7/couchdb/client.pyc in _fetch(self)
988
989 def _fetch(self):
--> 990 data = self.view._exec(self.options)
991 wrapper = self.view.wrapper or Row
992 self._rows = [wrapper(row) for row in data['rows']]
/usr/lib/pymodules/python2.7/couchdb/client.pyc in _exec(self, options)
912 _, _, data = self.resource.post_json(body=content, headers={
913 'Content-Type': 'application/json'
--> 914 }, **self._encode_options(options))
915 return data
916
/usr/lib/pymodules/python2.7/couchdb/http.pyc in post_json(self, *a, **k)
397
398 def post_json(self, *a, **k):
--> 399 status, headers, data = self.post(*a, **k)
400 if 'application/json' in headers.get('content-type'):
401 data = json.decode(data.read())
/usr/lib/pymodules/python2.7/couchdb/http.pyc in post(self, path, body,
headers, **params)
379 def post(self, path=None, body=None, headers=None, **params):
380 return self._request('POST', path, body=body,
headers=headers,
--> 381 **params)
382
383 def put(self, path=None, body=None, headers=None, **params):
/usr/lib/pymodules/python2.7/couchdb/http.pyc in _request(self, method,
path, body, headers, **params)
417 return self.session.request(method, url, body=body,
418 headers=all_headers,
--> 419 credentials=self.credentials)
420
421
/usr/lib/pymodules/python2.7/couchdb/http.pyc in request(self, method, url,
body, headers, credentials, num_redirects)
237 raise
238
--> 239 resp = _try_request_with_retries(iter(self.retry_delays))
240 status = resp.status
241
/usr/lib/pymodules/python2.7/couchdb/http.pyc in
_try_request_with_retries(retries)
203 except StopIteration:
204 # No more retries, raise last socket error.
--> 205 raise e
206 time.sleep(delay)
207 conn.close()
error: 104
In the /var/log/couchdb/couchdb.log I see a lot of log output. The most
interesting line here probably was:
<<"Traceback (most recent call last):\n File
\"/usr/lib/pymodules/python2.7/couchdb/view.py\", line 78, in map_doc\n
results.append([[key, value] for key, value in function(doc)])\n File
\"<string>\", line 2, in foo\nAttributeError: 'dict' object has no
attribute '_id'\n">>}]}}}]},
It appears as if the attributes starting with "_" are not getting passed
through.
---
What is the expected output? What do you see instead?
- I expected to get a view of all document IDs (_id) as keys.
- Instead I received an "error: 104".
---
What version of the product are you using? On what operating system?
- CouchDB 1.1.1
- python-couchdb 0.8-1
- Python 2.7.3