Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Issue 211 in couchdb-python: Cannot access _id and _doc attributes in a view written in Python
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
couchdb-pyt...@googlecode.com  
View profile  
 More options Apr 15 2012, 4:56 am
From: couchdb-pyt...@googlecode.com
Date: Sun, 15 Apr 2012 08:56:30 +0000
Local: Sun, Apr 15 2012 4:56 am
Subject: Issue 211 in couchdb-python: Cannot access _id and _doc attributes in a view written in Python
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
couchdb-pyt...@googlecode.com  
View profile  
 More options Apr 15 2012, 6:43 am
From: couchdb-pyt...@googlecode.com
Date: Sun, 15 Apr 2012 10:43:39 +0000
Local: Sun, Apr 15 2012 6:43 am
Subject: Re: Issue 211 in couchdb-python: Cannot access _id and _doc attributes in a view written in Python

Comment #1 on issue 211 by kxepal: Cannot access _id and _doc attributes in  
a view written in Python
http://code.google.com/p/couchdb-python/issues/detail?id=211

Hi,
This is not a problem: documents are represented as pure dicts in CouchDB  
Python query functions and do not have support of object notation access to  
attributes as Javascript one provides. Your map function should be
def foo(doc):
   yield doc['_id'], 42
to work properly.
Reason that error had raised on any attribute access is a specific of lazy  
initialization when temporary view had executed only when any information  
from it was requested.

P.S. q=some_database.query(map_fun=mapfunc) should also has language  
argument because default expected language of queries is javascript, not  
python.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
couchdb-pyt...@googlecode.com  
View profile  
 More options Apr 23 2012, 4:17 am
From: couchdb-pyt...@googlecode.com
Date: Mon, 23 Apr 2012 08:17:43 +0000
Local: Mon, Apr 23 2012 4:17 am
Subject: Re: Issue 211 in couchdb-python: Cannot access _id and _doc attributes in a view written in Python

Comment #2 on 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

Thank you!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
couchdb-pyt...@googlecode.com  
View profile  
 More options Oct 11 2012, 8:18 pm
From: couchdb-pyt...@googlecode.com
Date: Fri, 12 Oct 2012 00:18:11 +0000
Local: Thurs, Oct 11 2012 8:18 pm
Subject: Re: Issue 211 in couchdb-python: Cannot access _id and _doc attributes in a view written in Python
Updates:
        Status: WorksForMe

Comment #3 on issue 211 by kxepal: Cannot access _id and _doc attributes in  
a view written in Python
http://code.google.com/p/couchdb-python/issues/detail?id=211

(No comment was entered for this change.)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »