Feature Request: Add `_full_clean:bool=False` to `baker.make()`
Normal happy path tests should use valid objects, isn't it? But it's a not possible to avoid creation of invalid model instance in bakery. Because it doesn't call full_clean().
What's about to add a optional argument to activate full_clean() call?
That's is a +1000 IMHO too @jedie.
@amureki I'm a really supporter of @jedie point here. Actually, I feel that not calling full_clean is an undesired behavior in model-bakery.
It's super likely that we'll need a minor release after #544 since we've changed the internal behavior of the library in a way that breaks it previous usage. So, shouldn't we take the opportunity to add this new flag but, with the default behavior being that it's enabled. And, if people want to disable the full_clean (which by-passes Django's .create behavior for example), they should disable it themselves.
What do you think?
Hi @jedie and @berinhard!
Thanks for the proposal and the conversation here!
I did some research to confirm Django's behaviour, and indeed Django itself does not call full_clean() on object creation (this was done for backwards compatibility long ago, I believe). So model-bakery's current behaviour is actually aligned with Django's QuerySet.create() method, which also skips validation. See the https://docs.djangoproject.com/en/5.2/ref/models/instances/#validating-objects:
Note that full_clean() will NOT be called automatically when you call your model's save() method.
I appreciate the work done in PR #547, and I'm not against adding the _full_clean flag! However, I agree with keeping it False by default to:
- Stay consistent with Django's core behaviour
- Avoid breaking existing tests/code that may rely on creating invalid objects for edge-case testing
That said, I'm very curious to understand the use case better! What scenarios are you encountering where you need validated objects from the bakery?
Understanding your workflow would help us figure out if there are other improvements we could make to the library to support this pattern better.