Improve `restricted_parameters` validator to cover None case

Validator raised the following error in case of None as target

  AttributeError: 'NoneType' object has no attribute 'get'

Change-Id: I23b7231ccf2f9e6982612fc7733375190ab7fc98
This commit is contained in:
Andrey Kurilin 2020-05-07 15:50:23 +03:00
parent 166435fb4f
commit 9708b288df
1 changed files with 4 additions and 4 deletions

View File

@ -294,10 +294,10 @@ class RestrictedParametersValidator(validation.Validator):
def validate(self, context, config, plugin_cls, plugin_cfg): def validate(self, context, config, plugin_cls, plugin_cfg):
restricted_params = [] restricted_params = []
for param_name in self.params: for param_name in self.params:
args = config.get("args", {}) source = config.get("args", {})
a_dict, a_key = (args, self.subdict) if self.subdict else ( if self.subdict:
config, "args") source = source.get(self.subdict) or {}
if param_name in a_dict.get(a_key, {}): if param_name in source:
restricted_params.append(param_name) restricted_params.append(param_name)
if restricted_params: if restricted_params:
self.fail("You can't specify parameters '%s' in '%s'" % ( self.fail("You can't specify parameters '%s' in '%s'" % (