Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call evaluate_pre() instead of evaluate() on Maybe decider #1067

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion factory/declarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
21 changes: 21 additions & 0 deletions tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Loading