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

FuzzyChoice does not accept SelfAttribute #1050

Open
anentropic opened this issue Oct 28, 2023 · 0 comments
Open

FuzzyChoice does not accept SelfAttribute #1050

anentropic opened this issue Oct 28, 2023 · 0 comments

Comments

@anentropic
Copy link
Contributor

The problem

I wanted to do this:

class MyFactory(factory.Factory):
    class Params:
        country_code_choices = (
            "AU",
            "GB",
            "DE",
            "US",
        )

    country_code = factory.fuzzy.FuzzyChoice(factory.SelfAttribute("..country_code_choices"))

But I get: TypeError: 'SelfAttribute' object is not iterable

Proposed solution

The docs are a bit unclear where exactly SelfAttribute is valid to be used or not. Examples show it used as argument to other fields, seems a similar usage to what I tried.

So I'm not sure if this is a bug or just needs documenting.

Extra notes

I am using this workaround:

    country_code = factory.LazyAttribute(
        lambda o: randgen.choice(o.country_code_choices)
    )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant