report if we created db and don't fail if no attachments twisty
authorMark Hammond <mhammond@skippinet.com.au>
Mon, 30 Mar 2009 11:33:37 +1100
branchtwisty
changeset 142 904171c40909c7f8840bedd98e6154f4babee78d
parent 141 9aa5903c2e4eb77802b9f2a3b72679f04e5dcdc6
child 143 518d0a4f53d96363ad3b91b4234749bf895c8ff9
push id1
push userroot
push dateWed, 08 Apr 2009 01:46:05 +0000
report if we created db and don't fail if no attachments
server/python/junius/model.py
--- a/server/python/junius/model.py
+++ b/server/python/junius/model.py
@@ -302,16 +302,18 @@ class DocumentModel(object):
         logger.debug("saved multiple docs with result=%(ok)s", result)
         ds = []
         for dinfo, dattach in zip(result['new_revs'], attachments):
             if dattach:
                 ds.append(self._cb_save_attachments(dinfo, dattach))
         return defer.DeferredList(ds)
 
     def _cb_save_attachments(self, saved_doc, attachments):
+        if not attachments:
+            return saved_doc
         # Each time we save an attachment the doc gets a new revision number.
         # So we need to do them in a chain, passing the result from each to
         # the next.
         remaining = attachments.copy()
         # This is recursive, but that should be OK.
         return self._cb_save_next_attachment(saved_doc, remaining)
 
     def _cb_save_next_attachment(self, result, remaining):
@@ -384,15 +386,17 @@ def fab_db(whateva):
     db = get_db(couch_name, None)
     dbinfo = config.couches[couch_name]
 
     def _create_failed(failure, *args, **kw):
         failure.trap(twisted.web.error.Error)
         if failure.value.status != '412': # precondition failed.
             failure.raiseException()
         logger.info("couch database %(name)r already exists", dbinfo)
+        return False
 
     def _created_ok(d):
         logger.info("created new database")
+        return True
 
     return db.createDB(dbinfo['name']
                 ).addCallbacks(_created_ok, _create_failed
                 )