lanto03 / couchdb-python

Automatically exported from code.google.com/p/couchdb-python
Other
0 stars 0 forks source link

[maybe bug?] Bulk update does not execute unless return value is iterated #5

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
def update(self, documents):
    documents = list(documents)
    data = self.resource.post('_bulk_docs', content=documents)
    for idx, result in enumerate(data['results']):
        assert 'ok' in result # FIXME: how should error handling work here?
        doc = documents[idx]
        doc.update({'_id': result['id'], '_rev': result['rev']})
        yield doc

This won't perform the POST until the first result is asked for. I'm not
sure if this is a bug or intentional as iterating the result has other side
effects too.  It just seemed a bit spooky and confused me for a while.

If iterating is optional, I think something like the following would 
make sure the update is always called when the function is called while
preserving the current usage.

def update(self, documents):
        documents = list(documents)
        data = self.resource.post('_bulk_docs', content=documents)
        def foo():
            for idx, result in enumerate(data['results']):
                assert 'ok' in result # FIXME: how should error handling
work here?
                doc = documents[idx]
                doc.update({'_id': result['id'], '_rev': result['rev']})
                yield doc
        return foo()

Original issue reported on code.google.com by melk...@gmail.com on 6 Feb 2008 at 10:36

GoogleCodeExporter commented 8 years ago
Is there a way to get a patch for this pushed through? It should be a relatively
straightforward.

Original comment by paul.jos...@gmail.com on 27 Apr 2008 at 8:45

GoogleCodeExporter commented 8 years ago
This should be fixed by r68.

Original comment by cmlenz on 22 May 2008 at 7:49