Fix default handling with newer voluptious

It seems newer voluptuous passes the specified default value into the
verification method. Previously if data wasn't supplied it seems to have
not validated anything and returend the default. Anyway this means we
need to use a default value that matches our input type and manipulate
it on the output end the same way we would normal input.

We make this update in order to use newer voluptuous which will be
required when we switch to python3.10.

Change-Id: I64d9c8ac1334971f2d1c82f19ea675022635dc37
This commit is contained in:
Clark Boylan 2022-10-14 16:13:44 -07:00
parent 4a451287df
commit 7f9c7fdee2
2 changed files with 6 additions and 8 deletions

View File

@ -25,20 +25,18 @@ from grafana_dashboards.schema.template.query import Query
class Template(object): class Template(object):
def __init__(self): def __init__(self):
# TODO(pabelanger): This is pretty ugly, there much be a better way to self.defaults = []
# set default values.
self.defaults = {
'enabled': False,
'list': [],
}
def _validate(self): def _validate(self):
def f(data): def f(data):
res = self.defaults
if not isinstance(data, list): if not isinstance(data, list):
raise v.Invalid('Should be a list') raise v.Invalid('Should be a list')
res = {
'enabled': False,
'list': []
}
for template in data: for template in data:
res['enabled'] = True res['enabled'] = True
validate = Base().get_schema() validate = Base().get_schema()

View File

@ -4,4 +4,4 @@ python-slugify
PyYAML>=3.1.0 PyYAML>=3.1.0
requests requests
six>=1.6.0 six>=1.6.0
voluptuous<=0.10.5 voluptuous>0.10.5