Skip to content

factory.SelfAttribute not evaluated when passed as list? #1120

@Kagee

Description

@Kagee

Description

I am not sure if this is me using factory_boy wrong, or a bug. When i use a factory.SelfAttribute to pass a attribue to a provider it is evaluated if i pass it directly, but not if passed in a list (alone or with more factory.SelfAttribute's)

Model / Factory code
    # Money object generated: ¥2,748
    subtotal = factory.Faker("djmoney", currency=_currency)

    # money is Money object: ¥2,748 / <class 'djmoney.money.Money'>
    tax = factory.Faker(
        "djmoney",
        money=factory.SelfAttribute("..subtotal"),
        multiplier=0.25,
    )
    # Money is not list of Money objects as expected: 
    # [<SelfAttribute('subtotal', default=<class 'factory.declarations._UNSPECIFIED'>)>]
    # Also, the SelfAttribute says "subtotal" not "..subtotal" anymore?
    total = factory.Faker(
        "djmoney",
        money=[
            factory.SelfAttribute("..subtotal"),
            # factory.SelfAttribute("..tax"), # Same problem with one or more list items
        ],
    )

Notes

I think the custom provider i am using is irellevant, but its code can be found here: https://gitlab.com/Kagee/homelab-organizer/-/blob/develop/hlo/factories/providers/moneyprovider.py

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