@@ -350,6 +350,16 @@ def validate_condition_value(condition: Dict[str, Any], rule_name: str):
350
350
raise SchemaValidationError (f"'value' key must not be null, rule={ rule_name } " )
351
351
action = condition .get (CONDITION_ACTION , "" )
352
352
353
+ # maintenance: we may need a new design if we end up with more exceptions like datetime/time range
354
+ # e.g., visitor pattern, registry etc.
355
+ validator = getattr (
356
+ ConditionsValidator ,
357
+ f"_validate_{ action .lower ()} _value" ,
358
+ ConditionsValidator ._validate_noop_value ,
359
+ )
360
+
361
+ validator (value , rule_name )
362
+
353
363
# time actions need to be parsed to make sure date and time format is valid and timezone is recognized
354
364
if action == RuleAction .SCHEDULE_BETWEEN_TIME_RANGE .value :
355
365
ConditionsValidator ._validate_schedule_between_time_and_datetime_ranges (
@@ -365,12 +375,13 @@ def validate_condition_value(condition: Dict[str, Any], rule_name: str):
365
375
action ,
366
376
ConditionsValidator ._validate_datetime_value ,
367
377
)
368
- elif action == RuleAction .SCHEDULE_BETWEEN_DAYS_OF_WEEK .value :
369
- ConditionsValidator ._validate_schedule_between_days_of_week (value , rule_name )
370
- # modulo range condition needs validation on base, start, and end attributes
371
378
elif action == RuleAction .MODULO_RANGE .value :
372
379
ConditionsValidator ._validate_modulo_range (value , rule_name )
373
380
381
+ @staticmethod
382
+ def _validate_noop_value (* args , ** kwargs ):
383
+ return True
384
+
374
385
@staticmethod
375
386
def _validate_datetime_value (datetime_str : str , rule_name : str ):
376
387
date = None
@@ -408,7 +419,7 @@ def _validate_time_value(time: str, rule_name: str):
408
419
)
409
420
410
421
@staticmethod
411
- def _validate_schedule_between_days_of_week (value : Any , rule_name : str ):
422
+ def _validate_schedule_between_days_of_week_value (value : Any , rule_name : str ):
412
423
error_str = f"condition with a CURRENT_DAY_OF_WEEK action must have a condition value dictionary with 'DAYS' and 'TIMEZONE' (optional) keys, rule={ rule_name } " # noqa: E501
413
424
if not isinstance (value , dict ):
414
425
raise SchemaValidationError (error_str )
0 commit comments