From 7f9c7fdee2bcf50a7a6d0920b2361fb914773b8a Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Fri, 14 Oct 2022 16:13:44 -0700 Subject: [PATCH] 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 --- grafana_dashboards/schema/template/__init__.py | 12 +++++------- requirements.txt | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/grafana_dashboards/schema/template/__init__.py b/grafana_dashboards/schema/template/__init__.py index a2858bf..0d958be 100644 --- a/grafana_dashboards/schema/template/__init__.py +++ b/grafana_dashboards/schema/template/__init__.py @@ -25,20 +25,18 @@ from grafana_dashboards.schema.template.query import Query class Template(object): def __init__(self): - # TODO(pabelanger): This is pretty ugly, there much be a better way to - # set default values. - self.defaults = { - 'enabled': False, - 'list': [], - } + self.defaults = [] def _validate(self): def f(data): - res = self.defaults if not isinstance(data, list): raise v.Invalid('Should be a list') + res = { + 'enabled': False, + 'list': [] + } for template in data: res['enabled'] = True validate = Base().get_schema() diff --git a/requirements.txt b/requirements.txt index 23564cc..39dfcb2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,4 @@ python-slugify PyYAML>=3.1.0 requests six>=1.6.0 -voluptuous<=0.10.5 +voluptuous>0.10.5