Greeting problem

89 views
Skip to first unread message

Jacob Fenwick

unread,
May 3, 2011, 3:07:18 PM5/3/11
to couch...@googlegroups.com
I'm having an issue with printing out greetings.

Here is my greeting program:
===================
import datetime

from couchdbkit import *

class Greeting(Document):
    author = StringProperty()
    content = StringProperty()
    date = DateTimeProperty()

# server object
server = Server()

# create database
db = server.get_or_create_db("greeting")

# associate Greeting to the db
Greeting.set_db(db)

# create a new greet
greet = Greeting(
    author="Benoit",
    content="Welcome to couchdbkit world",
    date=datetime.datetime.utcnow()
)

# save it
greet.save()

greet.author = "Jacob Fenwick"
greet.save()

greet.homepage = "http://www.jacobfenwick.com"
greet.save()

push('_design/greeting', db)

greets = Greeting.view('greeting/all')
print list(greets)

===============

Here's map.js:
$ cat _design/greeting/views/all/map.js
function(doc) {
  if (doc.doc_type == “Greeting”)
    emit(doc._id, doc);
}

=================

And here's the error I get when I run the greeting program:
$ python create.pyTraceback (most recent call last):
  File "create.py", line 38, in <module>
    print list(greets)
  File "/Library/Python/2.6/site-packages/couchdbkit-0.5.4-py2.6.egg/couchdbkit/client.py", line 842, in iterator
    self._fetch_if_needed()
  File "/Library/Python/2.6/site-packages/couchdbkit-0.5.4-py2.6.egg/couchdbkit/client.py", line 921, in _fetch_if_needed
    self.fetch()
  File "/Library/Python/2.6/site-packages/couchdbkit-0.5.4-py2.6.egg/couchdbkit/client.py", line 903, in fetch
    self._result_cache = self.view._exec(**self.params).json_body
  File "/Library/Python/2.6/site-packages/couchdbkit-0.5.4-py2.6.egg/couchdbkit/client.py", line 991, in _exec
    return self._db.res.get(self.view_path, **params)
  File "build/bdist.macosx-10.6-universal/egg/restkit/resource.py", line 113, in get
  File "/Library/Python/2.6/site-packages/couchdbkit-0.5.4-py2.6.egg/couchdbkit/resource.py", line 108, in request
    payload=payload, headers=headers, **params)
  File "build/bdist.macosx-10.6-universal/egg/restkit/resource.py", line 207, in request
restkit.errors.RequestFailed: {"error":"compilation_error","reason":"Expression does not eval to a function. ((new String(\"function(doc) { \\n  if (doc.doc_type == \\u201CGreeting\\u201D) \\n    emit(doc._id, doc); \\n}\")))"}

=================

I've noticed there's a 404 error during the call when it pushes the view to couchdb:
[info] [<0.585.0>] 127.0.0.1 - - 'HEAD' /greeting/ 200
[info] [<0.585.0>] 127.0.0.1 - - 'GET' /greeting/_design/greeting 404
[info] [<0.585.0>] 127.0.0.1 - - 'PUT' /greeting/_design/greeting 201


Any insight into what I can do to solve this problem?

I'm running on OS X in case that makes a difference.

Jacob

Benoit Chesneau

unread,
May 3, 2011, 4:28:31 PM5/3/11
to couchdbkit
Hi Jacob,

This is a javascript error in CouchDB. Apparently your function isn't
good. Can paste it here ?

The 404 error is harmless, couchdbkit use it to detect if the doc
already exists and need update.

- benoît

Jacob Fenwick

unread,
May 3, 2011, 4:45:39 PM5/3/11
to couch...@googlegroups.com
By function you mean the JavaScript map function, correct?

The JavaScript function is contained in map.js which I pasted in my first email.

Thanks for your prompt response.

> --
> You received this message because you are subscribed to the Google Groups "couchdbkit" group.
> To post to this group, send email to couch...@googlegroups.com.
> To unsubscribe from this group, send email to couchdbkit+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/couchdbkit?hl=en.
>
>

Jacob Fenwick

unread,
May 4, 2011, 9:59:33 AM5/4/11
to couch...@googlegroups.com
Here's how it shows up in http://localhost:5984/_utils/document.html?greeting/_design/greeting:
_id_design/greeting
_rev1-28f04cdfb14d1b03bfe6d7c1b7b43b8a
couchapp
signatures
{ }
objects
{ }
manifest
views
all
map
function(doc) {
if (doc.doc_type == “Greeting”)
emit(doc._id, doc);
}

Jacob

Doug Latornell

unread,
May 4, 2011, 10:25:54 AM5/4/11
to couch...@googlegroups.com
Hi Jacob;

The traceback certainly indicates that there is a syntax error in the map.js function, but for the life of me I can't see it.

Doug

Benoit Chesneau

unread,
May 4, 2011, 10:30:46 AM5/4/11
to couchdbkit


On May 4, 3:59 pm, Jacob Fenwick <jacob.fenw...@gmail.com> wrote:
> Here's how it shows up inhttp://localhost:5984/_utils/document.html?greeting/_design/greeting:
> *_id*_design/greeting*_rev*1-28f04cdfb14d1b03bfe6d7c1b7b43b8a*couchapp*
> signatures{ }objects{ }manifest*views*allmapfunction(doc) {
> if (doc.doc_type == “Greeting”)
> emit(doc._id, doc);}
>
> Jacob
>
The quotes around Greeting look suspect to me. but could be just mail
formatting.

- benoît

Jacob Fenwick

unread,
May 4, 2011, 10:42:17 AM5/4/11
to couch...@googlegroups.com
Aha! That was the culprit.
Those quotes on the Getting Started page are quite deadly.
I thought I managed to turn them all into proper double quotes but I missed those two.
Did you intentionally use those weird quotes or am I getting those because I'm using Google Chrome?

I have some suggestions for the Getting Started:
Turn those weird quotes into normal quotes.
Get rid of the single character of whitespace at the front of each piece of code.
Or alternatively, provide a Github style 'Copy Code' button at the top of each code block.

It also might help to provide one line at the end that prints out data from the returned greets object.

Thanks for the help,

Jacob


- benoît

Reply all
Reply to author
Forward
0 new messages