FileSystemDocsLoader error

68 views
Skip to first unread message

Adam Cox

unread,
May 27, 2011, 6:19:14 AM5/27/11
to couch...@googlegroups.com
Hi all.  I am getting an error when trying to upload design documents. 

Here is my python script:

from couchdbkit import *
import sys

if __name__ == '__main__':
    uri = sys.argv[1]
    dbname = sys.argv[2]
    print uri, dbname

    s = Server(uri)
    db = s.get_or_create_db(dbname)
    print db

    loader = FileSystemDocsLoader('_design')
    loader.sync(db, verbose=True)


And this script is run in a directory where the folder "_design" exists. Inside _design is

_design:
      language
      views:
           daqmap:
                map.js
                reduce.js
           hvlog:
                map.js
                reduce.js

When I run the script, I get the following error:

12:13pm adam:./uploadToDb.py http://xxx.xxx.xxx.xxx:5984 testdb
<Database testdb>
Traceback (most recent call last):
  File "./uploadToDb.py", line 17, in <module>
    loader.sync(db, verbose=True)
  File "/Library/Python/2.6/site-packages/couchdbkit-0.5.2-py2.6.egg/couchdbkit/loaders.py", line 87, in sync
    pushapps(path, dbs, atomic=atomic)
  File "/Library/Python/2.6/site-packages/couchdbkit-0.5.2-py2.6.egg/couchdbkit/designer/fs.py", line 432, in pushapps
    doc['_rev'] = db.last_rev(doc['_id'])
AttributeError: 'Database' object has no attribute 'last_rev'


I swear that this used to work for me in the past, but now I can't figure out what is wrong.

Thanks in advance for your help!
Adam

Adam Cox

unread,
May 27, 2011, 6:25:36 AM5/27/11
to couch...@googlegroups.com
I upgraded to 0.5.4 and the error is still there. 


Adam

Benoit Chesneau

unread,
May 27, 2011, 10:35:53 AM5/27/11
to couch...@googlegroups.com

On May 27, 2011, at 12:25 PM, Adam Cox wrote:

> I upgraded to 0.5.4 and the error is still there.
>
>
> Adam
>

Thanks adam,

I will check it later in the night here. Did you test with last head?

- benoît

Adam Cox

unread,
May 27, 2011, 1:08:35 PM5/27/11
to couch...@googlegroups.com
Hi... no I didn't try with the latest version. 

Adam Cox

unread,
May 28, 2011, 11:15:47 AM5/28/11
to couch...@googlegroups.com
my directory structure under _design is actually this:

_design:
      muonveto:
Message has been deleted

Doug Latornell

unread,
May 29, 2011, 8:34:53 PM5/29/11
to couch...@googlegroups.com
I saw the same error a few days ago when I upgraded an app from couchdbkit 0.4.11 to dev tip. I didn't have time to dig into the library for the cause any deeper than to figure out that FileSystemDocsLoader('_design') appears to be not iterating over the views directories in the same way it used to. I was able to work around the problem by changing my code from:
from couchdbkit.loaders import FileSystemDocsLoader
          loader = FileSystemDocsLoader(design_docs_path)
          loader.sync(database)

to:
from couchdbkit.designer import push
          base_path = design_docs_path
          for design_docs_dir in os.listdir(base_path):
              docs_path = os.path.join(base_path, design_docs_dir)
              push(docs_path, database)

Benoit Chesneau

unread,
Jun 2, 2011, 2:16:21 AM6/2/11
to couchdbkit
Have you put a ".couchapprc" in your folders ? This is how it works
now to know if an app is an app. Would it be better if the system
doesn't rely on it ?

- benoît

Adam Cox

unread,
Jun 2, 2011, 8:36:29 AM6/2/11
to couch...@googlegroups.com
Hi..
I don't have a .couchapprc file in any of the _design folders.

And now... I'm sorry to report, I can't reproduce my error!!

Adam

> --
> 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.
>

Ceri Storey

unread,
Jun 4, 2011, 6:36:59 AM6/4/11
to couch...@googlegroups.com
Hi Benoit and co.

I've seen this error triggered when the credentials specified to couchdb (or lack therof) don't have admin privileges, and thereby isn't able to write to the design documents.

In one case, couchdbkit.designer.fs:pushapps, any BulkSaveError from Database.save_docs() is caught, under the assumption that there is an existing design document of that name. However, it looks like in this case the exception raised by Database.save_docs() is a little overly-course, in this case corresponding to the following response-body from couchdb:

HTTP/1.1 201 Created
Server: CouchDB/1.0.1 (Erlang OTP/R13B)
Date: Sat, 04 Jun 2011 10:30:00 GMT
Content-Type: application/json
Content-Length: 203
Cache-Control: must-revalidate

[{"id":"_design/kingschamber","error":"unauthorized","reason":"You are not a db or server admin."},{"id":"_design/kingschamber_mgmt","error":"unauthorized","reason":"You are not a db or server admin."}]

(Admittedly, it's quite difficult to handle this well as there are multiple error cases to handle and you can only ever throw a single exception at once). 

That said, I can't see that the method used to recover (Database.last_rev()) in this case is actually defined anywhere in the couchdbkit source code; I guess this is just an oversight. 

Anyway, I hope this is useful.
Reply all
Reply to author
Forward
0 new messages