From: Debian Python Modules Team
 <python-modules-team@lists.alioth.debian.org>
Date: Thu, 15 Aug 2019 22:32:19 +0500
Subject: Backport compatibility with python 3.7.

Origin: upstream, https://github.com/FactoryBoy/factory_boy/commit/97f48597d241aca598783f7bcaed34bf7b133343#diff-0be885856f4589792f278830f0e79cac
Applied-Upstream: https://github.com/FactoryBoy/factory_boy/commit/97f48597d241aca598783f7bcaed34bf7b133343#diff-0be885856f4589792f278830f0e79cac
Reviewed-by: Joseph Herlant <aerostitch@debian.org>
Last-Update: 2019-01-06

This has been merged upstream for a while but no release has been cut
in a long time. As causing an FTBS on Debian, backporting this.
Last-Update: 2019-01-06
---
 factory/utils.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/factory/utils.py b/factory/utils.py
index 75f352b..cf38f38 100644
--- a/factory/utils.py
+++ b/factory/utils.py
@@ -133,9 +133,13 @@ class ResetableIterator(object):
             if self.next_elements:
                 yield self.next_elements.popleft()
             else:
-                value = next(self.iterator)
-                self.past_elements.append(value)
-                yield value
+                try:
+                    value = next(self.iterator)
+                except StopIteration:
+                    break
+                else:
+                    self.past_elements.append(value)
+                    yield value
 
     def reset(self):
         self.next_elements.clear()
