Skip to content

FuzzyChoice does not accept SelfAttribute #1050

Open

Description

@anentropic

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)
    )

Activity

  1. added 2 commits that reference this issue on Jan 9, 2026
    73464eb
    31e43ae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions