diff --git a/factory/declarations.py b/factory/declarations.py index 70abe35c..951b45f3 100644 --- a/factory/declarations.py +++ b/factory/declarations.py @@ -536,7 +536,7 @@ def evaluate_post(self, instance, step, overrides): return target def evaluate_pre(self, instance, step, overrides): - choice = self.decider.evaluate(instance=instance, step=step, extra={}) + choice = self.decider.evaluate_pre(instance=instance, step=step, overrides={}) target = self.yes if choice else self.no # The value can't be POST_INSTANTIATION, checked in __init__; # evaluate it as `evaluate_pre` diff --git a/tests/test_regression.py b/tests/test_regression.py index a9ea1c66..2cca0bda 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -51,3 +51,24 @@ class Params: unknown_author = AuthorFactory(unknown=True) self.assertEqual("", unknown_author.fullname) + + def test_evaluated_without_locale(self): + """Regression test for `KeyError: 'locale'` raised in `evaluate`. + + See #965 + + """ + class AuthorFactory(factory.Factory): + fullname = factory.Faker("name") + pseudonym = factory.Maybe( + decider=factory.Faker("pybool"), + yes_declaration="yes", + no_declaration="no", + ) + + class Meta: + model = Author + + author = AuthorFactory() + + self.assertIn(author.pseudonym, ["yes", "no"])