lanto03 / couchdb-python

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

Exception mapping view results to Object derived from schema.Document #38

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. couchdb from source, svn Revision: 720997
2. couchdb-python from source, svn Revision: 130
3. python 2.6 on mac os x 10.5
4. run the att'd script: python break.py

Please provide any additional information below.

run the att'd script and you'll see that there's an exception thrown in mapping 
view results back to 
the User object that is derived from schema. 

Original issue reported on code.google.com by mlmiller...@gmail.com on 29 Nov 2008 at 10:02

Attachments:

GoogleCodeExporter commented 8 years ago
The referenced line of code:

++ data = row.value
++ data['_id'] = row.id

suggests that row.value should be a dict or an object with dict-like properties.

The corresponding view docstring seems out of synch ...

>>> print Person.by_name.map_fun
function(doc) {
    emit(doc.name, doc.age);
}

Elsewhere, examples show

emit(doc.name, null);

and indeed, the raw _view output correspondingly shows value=None.

I had some success using a dict as a workaround, along the lines of the 
following, when defining a view:

function(doc) {
    emit(doc.name, {'age':doc.age, 'name':doc.name} );
}

It's hardly a 'map back into the object' but it does avoid the Exception 
condition. I haven't investigated any 
deeper than that simplistic change.

Original comment by gjhigg...@gmail.com on 3 Jan 2009 at 5:40

GoogleCodeExporter commented 8 years ago
After a little more investigation ... the view in the OP's attached script 
doesn't support the usage in the code. 
If the emit function is changed to:

emit(doc.name, doc);

then the OP's attached script executes without causing an Exception and the 
retrieved results do indeed 
behave as User objects, e.g.

print elem.name

HTH

Original comment by gjhigg...@gmail.com on 4 Jan 2009 at 2:16

GoogleCodeExporter commented 8 years ago
Looks like this isn't a couchdb-python problem.

Original comment by djc.ochtman on 8 Dec 2009 at 4:23