-
Notifications
You must be signed in to change notification settings - Fork 12
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
Fixed issue where config with *
could not be filled
#53
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f54e45
Fix field exclusion logic in registry class when validate is False
KennethEnevoldsen a6c9a50
Fix missing field alias issue in copy_model_field()
KennethEnevoldsen 74f7d6e
Add test for filling config positional args with
KennethEnevoldsen 7dde04d
chore: removed comment out code
KennethEnevoldsen d777cb4
formatted to black
KennethEnevoldsen 17e49ec
remove unused cfg
KennethEnevoldsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -704,6 +704,7 @@ def copy_model_field(field: ModelField, type_: Any) -> ModelField: | |
default=field.default, | ||
default_factory=field.default_factory, | ||
required=field.required, | ||
alias=field.alias, | ||
) | ||
|
||
|
||
|
@@ -912,6 +913,15 @@ def _fill( | |
# created via config blocks), only use its values | ||
validation[v_key] = list(validation[v_key].values()) | ||
final[key] = list(final[key].values()) | ||
|
||
if ARGS_FIELD_ALIAS in schema.__fields__ and not resolve: | ||
# If we're not resolving the config, make sure that the field | ||
# expecting the promise is typed Any so it doesn't fail | ||
# validation if it doesn't receive the function return value | ||
field = schema.__fields__[ARGS_FIELD_ALIAS] | ||
schema.__fields__[ARGS_FIELD_ALIAS] = copy_model_field( | ||
field, Any | ||
) | ||
Comment on lines
+921
to
+924
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a copy of a logic appearing earlier (if it is a promise). It seems like it might be possible to move it outside the 'if promise'-scope. |
||
else: | ||
filled[key] = value | ||
# Prevent pydantic from consuming generator if part of a union | ||
|
@@ -936,7 +946,12 @@ def _fill( | |
# manually because .construct doesn't parse anything | ||
if schema.Config.extra in (Extra.forbid, Extra.ignore): | ||
fields = schema.__fields__.keys() | ||
exclude = [k for k in result.__fields_set__ if k not in fields] | ||
# If we have a reserved field, we need to use its alias | ||
field_set = [ | ||
k if k != ARGS_FIELD else ARGS_FIELD_ALIAS | ||
for k in result.__fields_set__ | ||
] | ||
exclude = [k for k in field_set if k not in fields] | ||
exclude_validation = set([ARGS_FIELD_ALIAS, *RESERVED_FIELDS.keys()]) | ||
validation.update(result.dict(exclude=exclude_validation)) | ||
filled, final = cls._update_from_parsed(validation, filled, final) | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This avoids dropping the previous alias for
*