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

factory.Maybe doesn't work with factory.RelatedFactory #397

Closed
tonial opened this Issue Jul 31, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@tonial
Contributor

tonial commented Jul 31, 2017

I'm trying to set a RelatedFactoy combine with Maybe, so that it's only created if a condition is fulfiled .

class PaymentModeFactory(factory.DjangoModelFactory):
    class Meta:
        model = models.PaymentMode

    kind = enums.MANUAL
    authorization = factory.Maybe(
        factory.LazyAttribute(lambda o: o.kind = enums.WITH_AUTH),
        factory.RelatedFactory(PaymentModeAuthorizationFactory, 'payment_mode'),
    )

Whenever the Maybe condition is True (and only if True) the _create() method is given a authorization key in it's kwargs. The value is the RelatedFactory we defined.

@twheys

This comment has been minimized.

twheys commented Nov 14, 2017

By "does't work well" you mean it doesn't work at all :(

From reading the source, it seems that there are 'pre' and 'post' build steps. RelatedFactory and PostGeneration are both 'post' steps and everything else is a 'pre' step. By wrapping RelatedFactory in a maybe, it gets included as a 'pre' step, which is incorrect.

@tonial tonial changed the title from factory.Maybe doesn't work well with factory.RelatedFactory to factory.Maybe doesn't work with factory.RelatedFactory Nov 14, 2017

@tonial

This comment has been minimized.

Contributor

tonial commented Nov 14, 2017

Yes, indeed, it was a understatement. I've just changed the issue title to make it clearer.

@twheys

This comment has been minimized.

twheys commented Nov 14, 2017

I ran into this myself when using RelatedFactory in traits. I suppose it also wouldn't work with any other type of post declaration.

I am new to factory_boy but I will try my hand at it.

twheys added a commit to twheys/factory_boy that referenced this issue Nov 14, 2017

Fixes FactoryBoy#397 Added deferred declarations to BuildStep in orde…
…r to resolve Maybes as a pre-build step and potentially use a post-build declaration as the result

twheys added a commit to twheys/factory_boy that referenced this issue Nov 14, 2017

Fixes FactoryBoy#397 Added deferred declarations to BuildStep in orde…
…r to resolve Maybes as a pre-build step and potentially use a post-build declaration as the result

twheys added a commit to twheys/factory_boy that referenced this issue Nov 14, 2017

Fixes FactoryBoy#397 Added deferred declarations to BuildStep in orde…
…r to resolve Maybes as a pre-build step and potentially use a post-build declaration as the result

twheys added a commit to twheys/factory_boy that referenced this issue Nov 14, 2017

Merge pull request #1 from twheys/maybe_post_declarations
Fixes FactoryBoy#397 Added deferred declarations to BuildStep in order to resol…

twheys added a commit to twheys/factory_boy that referenced this issue Nov 14, 2017

Fixes FactoryBoy#397 Added deferred declarations to BuildStep in orde…
…r to resolve Maybes as a pre-build step and potentially use a post-build declaration as the result

twheys added a commit to twheys/factory_boy that referenced this issue Nov 14, 2017

Fixes FactoryBoy#397 Added deferred declarations to BuildStep in orde…
…r to resolve Maybes as a pre-build step and potentially use a post-build declaration as the result

twheys added a commit to twheys/factory_boy that referenced this issue Nov 14, 2017

Fixes FactoryBoy#397 Added deferred declarations to BuildStep in orde…
…r to resolve Maybes as a pre-build step and potentially use a post-build declaration as the result

twheys added a commit to twheys/factory_boy that referenced this issue Nov 14, 2017

Merge pull request #2 from twheys/maybe_post_declarations
Fixes FactoryBoy#397 Added deferred declarations to BuildStep in order to resol…

@rbarrois rbarrois closed this in 33d27c2 Jan 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment