-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
feat: allow use of the default value based on configuration #472
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
guacs
commented
Jan 4, 2024
adhtruong
reviewed
Jan 4, 2024
adhtruong
reviewed
Jan 5, 2024
Sometimes users may want to use the default value set on a field rather than create a random value. This allows users to configure that behavior. Also, for more fine-grained control, the users can override the 'should_use_default_value' method in order to change the behavior per field or however else they wish to do so.
By moving the check into `process_kwargs`, we can just safely avoid any edge cases that may arise from how the defaults are defined. If we should be using the default for a field, we can just not add it to the kwargs that we finally end up passing to the constructor of the model. This way, we ensure that the creation of the default value will happen normally however the underlying library (dataclasses, pydantic etc.) would handle it.
provinzkraut
approved these changes
Jan 13, 2024
Alc-Alc
reviewed
Jan 13, 2024
Co-authored-by: Alc-Alc <45509143+Alc-Alc@users.noreply.github.com>
Quality Gate passedKudos, no new issues were introduced! 0 New issues |
Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/472 |
@cofin thank you! :) |
When can we expect a new release with this functionality? 🙂 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
__use_defaults__
field on the class.BaseFactory.should_use_default_value
classmethod.Close Issue(s)