Calling store function causes AttributeError

8 views
Skip to first unread message

Mark

unread,
Jan 7, 2012, 1:57:44 PM1/7/12
to CouchDB-Python, zhen...@me.com
Hi,

1. I was following the examples for DictField in
http://packages.python.org/CouchDB/mapping.html

2. I wrote a small script to prevent me from typing things over and
over again, it looks like this:

-------------------------------------------
BEGIN--------------------------------------------------
from couchdb import Server, Document
from couchdb.mapping import TextField, IntegerField, DateTimeField,\
DictField, ListField, Mapping

class Post(Document):
name = TextField()
content = TextField()
author = DictField(Mapping.build(
name = TextField(),
email = TextField()
))
extra = DictField()

def create_server():
server = Server('http://xxxxxxxx:ABCDEFG@localhost:5984')
if 'python-tests' in server:
del server['python-tests']
db = server.create('python-tests')
return db
-------------------------------------------
END-------------------------------------------------

3. I wanted to test to see if I could add additional attributes/keys
to a Document mapping even after it has already been defined. I
created a new Post like such (age is the newly added attribute):

>>> post = Post(
... title='Foo bar',
... author=dict(name='John Doe',
... email='jo...@doe.com'),
... extra=dict(foo='bar'),
... age=42
... )

However, when I try to save the document into the db using
post.store(db), it errors out saying something like this:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Post' object has no attribute 'store'

And if I try to access the variable "post", it prints the following
error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.7-intel/egg/couchdb/client.py", line
933, in __repr__
File "build/bdist.macosx-10.7-intel/egg/couchdb/client.py", line
943, in id
KeyError: '_id'

4. Can someone please help me out, I'm really lost here. The strange
part about this is that, I went through these examples earlier in the
day and everything seemed to work.

5. Finally, for those curious, I am using CouchDB version 1.1.1 and
couchdb-python version 0.9a (the one from Mercurial, as I heard the
0.8 one had some bugs with ListField).

Thanks in advance.

Regards,
Mark Huang

Alexander Shorin

unread,
Jan 7, 2012, 3:56:39 PM1/7/12
to couchdb...@googlegroups.com, zhen...@me.com
Hi,

Everything is "fine", it's an quite know issue:
http://code.google.com/p/couchdb-python/issues/detail?id=195
http://code.google.com/p/couchdb-python/issues/detail?id=197

Problem is in


> from couchdb import Server, Document

try to change this line to
> from couchdb import Server
> from couchdb.mapping import Document


--
,,,^..^,,,

Mark

unread,
Jan 8, 2012, 1:48:16 PM1/8/12
to CouchDB-Python
Thank you so much for this and I am sorry for not discovering the
"known issue". I'm quite new to couchdb and trying to embrace it.

On Jan 8, 4:56 am, Alexander Shorin <kxe...@gmail.com> wrote:
> Hi,
>
> Everything is "fine", it's an quite know issue:http://code.google.com/p/couchdb-python/issues/detail?id=195http://code.google.com/p/couchdb-python/issues/detail?id=197
Reply all
Reply to author
Forward
0 new messages