@@ -121,38 +121,38 @@ def reduce_need(
121
121
122
122
if keep :
123
123
coerced_value = value
124
- if (
125
- schema_field ["field_type" ] == "extra"
126
- and field in config .extra_options
127
- and config .extra_options [field ].schema is not None
128
- and "type" in config .extra_options [field ].schema
129
- and config .extra_options [field ].schema ["type" ] != "string"
130
- ):
131
- type_ = config .extra_options [field ].schema ["type" ]
132
- if not isinstance (value , str ):
133
- raise ValueError (
134
- f"Field '{ field } ': cannot coerce '{ value } ' (type: { type (value )} ) to { type_ } "
135
- )
136
- try :
137
- if type_ == "integer" :
138
- coerced_value = int (value )
139
- if type_ == "number" :
140
- coerced_value = float (value )
141
- except ValueError as exc :
142
- raise ValueError (
143
- f"Field '{ field } ': cannot coerce '{ value } ' to { type_ } "
144
- ) from exc
145
- if type_ == "boolean" :
146
- truthy = {"true" , "yes" , "y" , "on" , "1" }
147
- falsy = {"false" , "no" , "n" , "off" , "0" }
148
- if value .lower () in truthy :
149
- coerced_value = True
150
- elif value .lower () in falsy :
151
- coerced_value = False
152
- else :
124
+ if schema_field ["field_type" ] == "extra" and field in config .extra_options :
125
+ option_schema = config .extra_options [field ].schema
126
+ if (
127
+ option_schema is not None
128
+ and "type" in option_schema
129
+ and option_schema ["type" ] != "string"
130
+ ):
131
+ type_ = option_schema ["type" ]
132
+ if not isinstance (value , str ):
153
133
raise ValueError (
154
- f"Field '{ field } ': cannot coerce '{ value } ' to boolean "
134
+ f"Field '{ field } ': cannot coerce '{ value } ' (type: { type ( value ) } ) to { type_ } "
155
135
)
136
+ try :
137
+ if type_ == "integer" :
138
+ coerced_value = int (value )
139
+ elif type_ == "number" :
140
+ coerced_value = float (value )
141
+ except ValueError as exc :
142
+ raise ValueError (
143
+ f"Field '{ field } ': cannot coerce '{ value } ' to { type_ } "
144
+ ) from exc
145
+ if type_ == "boolean" :
146
+ truthy = {"true" , "yes" , "y" , "on" , "1" }
147
+ falsy = {"false" , "no" , "n" , "off" , "0" }
148
+ if value .lower () in truthy :
149
+ coerced_value = True
150
+ elif value .lower () in falsy :
151
+ coerced_value = False
152
+ else :
153
+ raise ValueError (
154
+ f"Field '{ field } ': cannot coerce '{ value } ' to boolean"
155
+ )
156
156
reduced_need [field ] = coerced_value
157
157
158
158
return reduced_need
@@ -444,7 +444,11 @@ def validate_need(
444
444
needs = needs ,
445
445
all_type_schemas = all_type_schemas ,
446
446
type_schemas = [cast (SchemaType , linked_schema )],
447
- need_path = [* need_path , link_type , str (target_need_dict ["id" ])],
447
+ need_path = [
448
+ * need_path ,
449
+ link_type ,
450
+ str (target_need_dict ["id" ]),
451
+ ],
448
452
schema_path = [
449
453
* schema_path_new ,
450
454
"link_schema" ,
0 commit comments