summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Kotlyarov <a@koterpillar.com>2015-12-08 12:57:24 +1100
committerAlexey Kotlyarov <a@koterpillar.com>2015-12-08 12:57:24 +1100
commitf023e5a477668b8374a75c78e87d946b21a27f15 (patch)
tree8beda94203c6c2ee621fca21ffce2b48a536e949
parent819ffaf9efe0d5a3eee85afc847ceb6969242833 (diff)
downloadfactory-boy-f023e5a477668b8374a75c78e87d946b21a27f15.tar
factory-boy-f023e5a477668b8374a75c78e87d946b21a27f15.tar.gz
Don't leave AttributeBuilder in an inconsistent state on exceptions
When one of the LazyValues raises an exception, don't leave its name in __pending stack of the AttributeBuilder, preventing evaluation of any other LazyValues.
-rw-r--r--factory/containers.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/factory/containers.py b/factory/containers.py
index 0ae354b..ec33ca1 100644
--- a/factory/containers.py
+++ b/factory/containers.py
@@ -102,8 +102,10 @@ class LazyStub(object):
val = self.__attrs[name]
if isinstance(val, LazyValue):
self.__pending.append(name)
- val = val.evaluate(self, self.__containers)
- last = self.__pending.pop()
+ try:
+ val = val.evaluate(self, self.__containers)
+ finally:
+ last = self.__pending.pop()
assert name == last
self.__values[name] = val
return val