@@ -704,6 +704,7 @@ def copy_model_field(field: ModelField, type_: Any) -> ModelField:
704
704
default = field .default ,
705
705
default_factory = field .default_factory ,
706
706
required = field .required ,
707
+ alias = field .alias ,
707
708
)
708
709
709
710
@@ -912,6 +913,15 @@ def _fill(
912
913
# created via config blocks), only use its values
913
914
validation [v_key ] = list (validation [v_key ].values ())
914
915
final [key ] = list (final [key ].values ())
916
+
917
+ if ARGS_FIELD_ALIAS in schema .__fields__ and not resolve :
918
+ # If we're not resolving the config, make sure that the field
919
+ # expecting the promise is typed Any so it doesn't fail
920
+ # validation if it doesn't receive the function return value
921
+ field = schema .__fields__ [ARGS_FIELD_ALIAS ]
922
+ schema .__fields__ [ARGS_FIELD_ALIAS ] = copy_model_field (
923
+ field , Any
924
+ )
915
925
else :
916
926
filled [key ] = value
917
927
# Prevent pydantic from consuming generator if part of a union
@@ -936,7 +946,12 @@ def _fill(
936
946
# manually because .construct doesn't parse anything
937
947
if schema .Config .extra in (Extra .forbid , Extra .ignore ):
938
948
fields = schema .__fields__ .keys ()
939
- exclude = [k for k in result .__fields_set__ if k not in fields ]
949
+ # If we have a reserved field, we need to use its alias
950
+ field_set = [
951
+ k if k != ARGS_FIELD else ARGS_FIELD_ALIAS
952
+ for k in result .__fields_set__
953
+ ]
954
+ exclude = [k for k in field_set if k not in fields ]
940
955
exclude_validation = set ([ARGS_FIELD_ALIAS , * RESERVED_FIELDS .keys ()])
941
956
validation .update (result .dict (exclude = exclude_validation ))
942
957
filled , final = cls ._update_from_parsed (validation , filled , final )
0 commit comments