77 validates_schema ,
88 ValidationError as MarshmallowValidationError ,
99 decorators ,
10+ RAISE as RAISEUNKNOWNOPTION ,
1011)
1112from marshmallow .error_store import ErrorStore
1213
@@ -28,14 +29,14 @@ class RangeSchema(Schema):
2829 }
2930 """
3031
31- _min = fields .Field (attribute = "min" , data_key = "min" )
32- _max = fields .Field (attribute = "max" , data_key = "max" )
33- step = fields .Field ()
32+ _min = fields .Raw (attribute = "min" , data_key = "min" )
33+ _max = fields .Raw (attribute = "max" , data_key = "max" )
34+ step = fields .Raw ()
3435 level = fields .String (validate = [validate .OneOf (["warn" , "error" ])])
3536
3637
3738class ChoiceSchema (Schema ):
38- choices = fields .List (fields .Field )
39+ choices = fields .List (fields .Raw )
3940 level = fields .String (validate = [validate .OneOf (["warn" , "error" ])])
4041
4142
@@ -53,9 +54,9 @@ class ValueValidatorSchema(Schema):
5354
5455
5556class IsSchema (Schema ):
56- equal_to = fields .Field (required = False )
57- greater_than = fields .Field (required = False )
58- less_than = fields .Field (required = False )
57+ equal_to = fields .Raw (required = False )
58+ greater_than = fields .Raw (required = False )
59+ less_than = fields .Raw (required = False )
5960
6061 @validates_schema
6162 def just_one (self , data , ** kwargs ):
@@ -107,15 +108,12 @@ class BaseParamSchema(Schema):
107108 data_key = "type" ,
108109 )
109110 number_dims = fields .Integer (required = False , load_default = 0 )
110- value = fields .Field (required = True ) # will be specified later
111+ value = fields .Raw (required = True ) # will be specified later
111112 validators = fields .Nested (
112113 ValueValidatorSchema (), required = False , load_default = {}
113114 )
114115 indexed = fields .Boolean (required = False )
115116
116- class Meta :
117- ordered = True
118-
119117
120118class EmptySchema (Schema ):
121119 """
@@ -126,15 +124,6 @@ class EmptySchema(Schema):
126124 pass
127125
128126
129- class OrderedSchema (Schema ):
130- """
131- Same as `EmptySchema`, but preserves the order of its fields.
132- """
133-
134- class Meta :
135- ordered = True
136-
137-
138127class ValueObject (fields .Nested ):
139128 """
140129 Schema for value objects
@@ -182,16 +171,17 @@ class BaseValidatorSchema(Schema):
182171 class.
183172 """
184173
185- class Meta :
186- ordered = True
187-
188174 WRAPPER_MAP = {
189175 "range" : "_get_range_validator" ,
190176 "date_range" : "_get_range_validator" ,
191177 "choice" : "_get_choice_validator" ,
192178 "when" : "_get_when_validator" ,
193179 }
194180
181+ def __init__ (self , * args , ** kwargs ):
182+ self .pt_context = {}
183+ super ().__init__ (* args , ** kwargs )
184+
195185 def validate_only (self , data ):
196186 """
197187 Bypass deserialization and just run field validators. This is taken
@@ -208,21 +198,23 @@ def validate_only(self, data):
208198 field_errors = bool (error_store .errors )
209199 self ._invoke_schema_validators (
210200 error_store = error_store ,
211- pass_many = True ,
201+ pass_collection = True ,
212202 data = data ,
213203 original_data = data ,
214204 many = None ,
215205 partial = None ,
216206 field_errors = field_errors ,
207+ unknown = RAISEUNKNOWNOPTION ,
217208 )
218209 self ._invoke_schema_validators (
219210 error_store = error_store ,
220- pass_many = False ,
211+ pass_collection = False ,
221212 data = data ,
222213 original_data = data ,
223214 many = None ,
224215 partial = None ,
225216 field_errors = field_errors ,
217+ unknown = RAISEUNKNOWNOPTION ,
226218 )
227219 errors = error_store .errors
228220 if errors :
@@ -271,7 +263,7 @@ def validate_param(self, param_name, param_spec, raw_data):
271263 Do range validation for a parameter.
272264 """
273265 validate_schema = not getattr (
274- self .context ["spec" ], "_defer_validation" , False
266+ self .pt_context ["spec" ], "_defer_validation" , False
275267 )
276268 validators = self .validators (
277269 param_name , param_spec , raw_data , validate_schema = validate_schema
@@ -290,15 +282,15 @@ def validate_param(self, param_name, param_spec, raw_data):
290282 return warnings , errors
291283
292284 def field_keyfunc (self , param_name ):
293- data = self .context ["spec" ]._data [param_name ]
285+ data = self .pt_context ["spec" ]._data [param_name ]
294286 field = get_type (data , self .validators (param_name ))
295287 try :
296288 return field .cmp_funcs ()["key" ]
297289 except AttributeError :
298290 return None
299291
300292 def field (self , param_name ):
301- data = self .context ["spec" ]._data [param_name ]
293+ data = self .pt_context ["spec" ]._data [param_name ]
302294 return get_type (data , self .validators (param_name ))
303295
304296 def validators (
@@ -309,7 +301,7 @@ def validators(
309301 if raw_data is None :
310302 raw_data = {}
311303
312- param_info = self .context ["spec" ]._data [param_name ]
304+ param_info = self .pt_context ["spec" ]._data [param_name ]
313305 # sort keys to guarantee order.
314306 validator_spec = param_info .get ("validators" , {})
315307 validators = []
@@ -347,7 +339,7 @@ def _get_when_validator(
347339 when_param = when_dict ["param" ]
348340
349341 if (
350- when_param not in self .context ["spec" ]._data .keys ()
342+ when_param not in self .pt_context ["spec" ]._data .keys ()
351343 and when_param != "default"
352344 ):
353345 raise MarshmallowValidationError (
@@ -382,8 +374,8 @@ def _get_when_validator(
382374 )
383375 )
384376
385- _type = self .context ["spec" ]._data [oth_param ]["type" ]
386- number_dims = self .context ["spec" ]._data [oth_param ]["number_dims" ]
377+ _type = self .pt_context ["spec" ]._data [oth_param ]["type" ]
378+ number_dims = self .pt_context ["spec" ]._data [oth_param ]["number_dims" ]
387379
388380 error_then = (
389381 f"When { oth_param } {{when_labels}}{{ix}} is {{is_val}}, "
@@ -469,9 +461,9 @@ def _get_range_validator(
469461 )
470462
471463 def _sort_by_label_to_extend (self , vos ):
472- label_to_extend = self .context ["spec" ].label_to_extend
464+ label_to_extend = self .pt_context ["spec" ].label_to_extend
473465 if label_to_extend is not None :
474- label_grid = self .context ["spec" ]._stateless_label_grid
466+ label_grid = self .pt_context ["spec" ]._stateless_label_grid
475467 extend_vals = label_grid [label_to_extend ]
476468 return sorted (
477469 vos ,
@@ -533,9 +525,9 @@ def _get_related_value(
533525 # If comparing against the "default" value then get the current
534526 # value of the parameter being updated.
535527 if oth_param_name == "default" :
536- oth_param = self .context ["spec" ]._data [param_name ]
528+ oth_param = self .pt_context ["spec" ]._data [param_name ]
537529 else :
538- oth_param = self .context ["spec" ]._data [oth_param_name ]
530+ oth_param = self .pt_context ["spec" ]._data [oth_param_name ]
539531 vals = oth_param ["value" ]
540532 labs_to_check = {k for k in param_spec if k not in ("value" , "_auto" )}
541533 if labs_to_check :
@@ -560,11 +552,11 @@ def _check_ndim_restriction(
560552 if other_param is None :
561553 continue
562554 if other_param == "default" :
563- ndims = self .context ["spec" ]._data [param_name ][
555+ ndims = self .pt_context ["spec" ]._data [param_name ][
564556 "number_dims"
565557 ]
566558 else :
567- ndims = self .context ["spec" ]._data [other_param ][
559+ ndims = self .pt_context ["spec" ]._data [other_param ][
568560 "number_dims"
569561 ]
570562 if ndims > 0 :
0 commit comments