-
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
Changes from 3 commits
2f54e45
a6c9a50
74f7d6e
7dde04d
d777cb4
17e49ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -692,6 +692,7 @@ def alias_generator(name: str) -> str: | |
return name | ||
|
||
|
||
|
||
def copy_model_field(field: ModelField, type_: Any) -> ModelField: | ||
"""Copy a model field and assign a new type, e.g. to accept an Any type | ||
even though the original value is typed differently. | ||
|
@@ -704,6 +705,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 +914,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 +947,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__ | ||
] | ||
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. If validate=False this avoid removing the "*" key. |
||
# field_set = 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) | ||
|
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
*