Skip to content
This repository has been archived by the owner on Jul 22, 2019. It is now read-only.

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

Closed
djc opened this issue Jul 12, 2014 · 2 comments
Closed
Labels

Comments

@djc
Copy link
Owner

djc commented Jul 12, 2014

From melk...@gmail.com on February 06, 2008 23:36:14

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: http://code.google.com/p/couchdb-python/issues/detail?id=5

@djc
Copy link
Owner Author

djc commented Jul 12, 2014

From paul.jos...@gmail.com on April 27, 2008 13:45:10

Is there a way to get a patch for this pushed through? It should be a relatively
straightforward.

@djc
Copy link
Owner Author

djc commented Jul 12, 2014

From cmlenz on May 22, 2008 12:49:05

This should be fixed by r68 .

Status: Fixed
Owner: cmlenz

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant