Skip to content

Commit 63e8672

Browse files
committed
Few small hotfixes
1 parent b3504c1 commit 63e8672

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

hatch_build/cli.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _recurse_add_fields(parser: ArgumentParser, model: Union["BaseModel", Type["
9494

9595
def parse_extra_args_model(model: "BaseModel"):
9696
try:
97-
from pydantic import BaseModel, TypeAdapter
97+
from pydantic import BaseModel, TypeAdapter, ValidationError
9898
except ImportError:
9999
raise ImportError("pydantic is required to use parse_extra_args_model")
100100
# Recursively parse fields from a pydantic model and its sub-models
@@ -139,16 +139,22 @@ def parse_extra_args_model(model: "BaseModel"):
139139

140140
# Convert the value using the type adapter
141141
if get_origin(field.annotation) in (list, List):
142-
value = adapter.validate_python(value.split(","))
142+
value = value or ""
143+
value = value.split(",")
143144
elif get_origin(field.annotation) in (dict, Dict):
145+
value = value or ""
144146
dict_items = value.split(",")
145147
dict_value = {}
146148
for item in dict_items:
147-
k, v = item.split("=", 1)
148-
dict_value[k] = v
149-
value = adapter.validate_python(dict_value)
150-
else:
149+
if item:
150+
k, v = item.split("=", 1)
151+
dict_value[k] = v
152+
value = dict_value
153+
try:
151154
value = adapter.validate_python(value)
155+
except ValidationError:
156+
_log.warning(f"Failed to validate field '{key}' with value '{value}' for model '{model_to_set.__class__.__name__}'")
157+
continue
152158

153159
# Set the value on the model
154160
setattr(model_to_set, key, value)

0 commit comments

Comments
 (0)