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
PostGeneration extracted = None vs not given #476
Comments
I do have the very same need and this use case seems quite "usual" to me. So the class responsible for this is: factory_boy/factory/declarations.py Lines 605 to 623 in 06d50e4
There is a value on the context, For now I'm relying on using an extra context arg... which gives (pseudo code):
This will give the following behaviors: The most confusing one:
The not so pretty and full of indirection:
The 2 most obvious:
I looked in the code quite a bit but I'm not sure from a design point of view if and how we could implement this? I was thinking of passing a new field to the post generation function, something like We could also make this behavior optional by passing an argument to the decorator:
If you don't mind providing some guidance I'm open to submit a PR and improve this very case 😉 Thanks. |
Thanks for reviving this issue! Indeed, the API for passing complex arguments to I'm wondering whether we should split it up:
For those questions, I like to start from the kind of API one would expect when using the factory; I'm thinking of those: # Provide parameters to the "publish" action
ProfileFactory(publish__targets=[1, 2, 3])
# Decide whether to publish
ProfileFactory(publish=False)
# Override the default values
ProfileFactory(groups=['admin', 'testers'])
# If empty, equivalent to:
ProfileFactory(groups=['users']) Do you see other usage patterns that should be covered beyond these call-side APIs? |
Just making sure that I read you correctly. Case 1You would have one case where the And your example allows to provide kwargs to that action:
Case 2The other case would be changing the value of a model field after the model is created, in this case it is:
So I believe the specific case for this issue would belong to case 2:
Do you have any ideas on how that could look in the declaration? |
I've come across a case where, with post_generation, I can't tell if no value was given upon creation in order to be extracted, or if the value given was
None
. It's set up sort of like the following.I'd like to be able to tell the difference between
FooFactory.create()
andFooFactory.create(bar=None)
, such thatFooFactory.create().bar == <faked_value>
andFooFactory.create(bar=None).bar == None
Unless I'm missing something, it doesn't seem like there's a way to do this.
The text was updated successfully, but these errors were encountered: