Skip to content

Commit

Permalink
Add a more prominent warning in the documentation on defective results
Browse files Browse the repository at this point in the history
of client.searchChunked() when the content of ICAT changes in between.
  • Loading branch information
RKrahl committed Jan 10, 2020
1 parent dad6078 commit 52363fd
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions icat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,39 @@ def searchChunked(self, query, skip=0, count=None, chunksize=100):
return value is an iterator over the items in the search
result rather then a list. The individual search calls are
done lazily, e.g. they are not done until needed to yield the
next item from the iterator. The result may be defective
(omissions, duplicates) if the content in the ICAT server
changes between individual search calls in a way that would
affect the result.
next item from the iterator.
.. note::
The result may be defective (omissions, duplicates) if the
content in the ICAT server changes between individual
search calls in a way that would affect the result. It is
a common mistake when looping over items returned from
this method to have code with side effects on the search
result in the body of the loop. Example:
.. code-block:: python
# Mark all datasets as complete
# This will *not* work as expected!
query = Query(client, "Dataset", conditions={
"complete": "= False"
}, includes="1", order=["id"])
for ds in client.searchChunked(query):
ds.complete = True
ds.update()
This should rather be formulated as:
.. code-block:: python
# Mark all datasets as complete
# This version works!
query = Query(client, "Dataset", includes="1", order=["id"])
for ds in client.searchChunked(query):
if not ds.complete:
continue
ds.complete = True
ds.update()
:param query: the search query.
:type query: :class:`icat.query.Query` or :class:`str`
Expand Down

0 comments on commit 52363fd

Please sign in to comment.