11from __future__ import annotations
22
33import json
4+ import logging
45from typing import (
56 Any ,
67 Callable ,
@@ -87,7 +88,7 @@ def isValid(self) -> bool:
8788 all required conditions; otherwise, returns False.
8889 """
8990 try :
90- self .validateData (self . _data )
91+ self .validateData ()
9192
9293 except ValidationError as e :
9394 self ._errors = e .args [0 ]
@@ -133,9 +134,9 @@ def wrapper(
133134 validated_data = input_filter .validateData ()
134135
135136 if input_filter ._model_class is not None :
136- validated_data = input_filter .serialize ()
137-
138- g .validated_data = validated_data
137+ g . validated_data = input_filter .serialize ()
138+ else :
139+ g .validated_data = validated_data
139140
140141 except ValidationError as e :
141142 return Response (
@@ -144,6 +145,13 @@ def wrapper(
144145 mimetype = "application/json" ,
145146 )
146147
148+ except Exception :
149+ logging .getLogger (__name__ ).exception (
150+ "An unexpected exception occurred while "
151+ "validating input data." ,
152+ )
153+ return Response (status = 500 )
154+
147155 return f (* args , ** kwargs )
148156
149157 return wrapper
@@ -175,7 +183,6 @@ def validateData(
175183 logical steps execution of the respective fields or conditions
176184 will propagate without explicit handling here.
177185 """
178- validated_data = self ._validated_data
179186 data = data or self ._data
180187 errors = {}
181188
@@ -193,11 +200,11 @@ def validateData(
193200
194201 try :
195202 if copy :
196- value = validated_data .get (copy )
203+ value = self . _validated_data .get (copy )
197204
198205 if external_api :
199206 value = self ._ExternalApiMixin__callExternalApi (
200- external_api , fallback , validated_data
207+ external_api , fallback , self . _validated_data
201208 )
202209
203210 value = self ._FilterMixin__applyFilters (filters , value )
@@ -215,18 +222,17 @@ def validateData(
215222 field_name , required , default , fallback , value
216223 )
217224
218- validated_data [field_name ] = value
225+ self . _validated_data [field_name ] = value
219226
220227 except ValidationError as e :
221228 errors [field_name ] = str (e )
222229
223230 try :
224- self ._ConditionMixin__checkConditions (validated_data )
231+ self ._ConditionMixin__checkConditions (self . _validated_data )
225232 except ValidationError as e :
226233 errors ["_condition" ] = str (e )
227234
228235 if errors :
229236 raise ValidationError (errors )
230237
231- self ._validated_data = validated_data
232- return validated_data
238+ return self ._validated_data
0 commit comments