Skip to content

Commit 909274f

Browse files
committed
[IMP] orm: make iter_browse accept a generator as ids
This allows the caller to be memory efficient on huge numbers of ids, allowing for even mor millions of records to be browsed.
1 parent 13adede commit 909274f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/util/orm.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class iter_browse(object):
371371
372372
:param model: the model to iterate
373373
:type model: :class:`odoo.model.Model`
374-
:param list(int) ids: list of IDs of the records to iterate
374+
:param iterable(int) ids: iterable of IDs of the records to iterate
375375
:param int chunk_size: number of records to load in each iteration chunk, `200` by
376376
default
377377
:param logger: logger used to report the progress, by default
@@ -391,7 +391,12 @@ def __init__(self, model, *args, **kw):
391391
self._model = model
392392
self._cr_uid = args[:-1]
393393
ids = args[-1]
394-
self._size = len(ids)
394+
self._size = kw.pop("size", None)
395+
if not self._size:
396+
try:
397+
self._size = len(ids)
398+
except TypeError:
399+
raise ValueError("When passing ids as a generator, the size kwarg is mandatory")
395400
self._chunk_size = kw.pop("chunk_size", 200) # keyword-only argument
396401
self._logger = kw.pop("logger", _logger)
397402
self._strategy = kw.pop("strategy", "flush")

0 commit comments

Comments
 (0)