Skip to content
This repository has been archived by the owner on Jul 22, 2019. It is now read-only.

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

Closed
djc opened this issue Jul 12, 2014 · 3 comments
Closed

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

djc opened this issue Jul 12, 2014 · 3 comments
Labels

Comments

@djc
Copy link
Owner

djc commented Jul 12, 2014

From mlmiller...@gmail.com on November 29, 2008 23:02:53

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.

Attachment: break.py

Original issue: http://code.google.com/p/couchdb-python/issues/detail?id=38

@djc
Copy link
Owner Author

djc commented Jul 12, 2014

From gjhigg...@gmail.com on January 03, 2009 09:40:36

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.

@djc
Copy link
Owner Author

djc commented Jul 12, 2014

From gjhigg...@gmail.com on January 04, 2009 06:16:04

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

@djc
Copy link
Owner Author

djc commented Jul 12, 2014

From djc.ochtman on December 08, 2009 08:23:17

Looks like this isn't a couchdb-python problem.

Status: Invalid

@djc djc closed this as completed Jul 12, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant