From 8b42e888175239fdac93b408e627bea0533f6473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 29 May 2019 11:00:27 +0200 Subject: [PATCH] Cerberus 1.3 renamed '{value,key}schema' to '{values,keys}rules' 'valueschema' and 'keyschema' have been replaced by 'valuesrules' and 'keysrules'. Note the change from 2x singular ('value' and 'schema') to 2x plural ('values' and 'rules'). --- pillar/api/custom_field_validation.py | 6 +++++- pillar/api/eve_settings.py | 4 ++-- pillar/api/node_types/__init__.py | 5 ++--- pillar/web/nodes/attachments.py | 13 +++++++++++-- tests/test_cli/test_maintenance.py | 4 ++-- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/pillar/api/custom_field_validation.py b/pillar/api/custom_field_validation.py index 70a205f8..bdd35ff2 100644 --- a/pillar/api/custom_field_validation.py +++ b/pillar/api/custom_field_validation.py @@ -29,7 +29,11 @@ class ValidateCustomFields(Validator): dict_valueschema = schema_prop['schema'] properties[prop] = self.convert_properties(properties[prop], dict_valueschema) except KeyError: - dict_valueschema = schema_prop['valueschema'] + # Cerberus 1.3 changed valueschema to valuesrules. + dict_valueschema = schema_prop.get('valuesrules') or \ + schema_prop.get('valueschema') + if dict_valueschema is None: + raise KeyError(f"missing 'valuesrules' key in schema of property {prop}") self.convert_dict_values(properties[prop], dict_valueschema) elif prop_type == 'list': diff --git a/pillar/api/eve_settings.py b/pillar/api/eve_settings.py index 3994130d..c84d71cd 100644 --- a/pillar/api/eve_settings.py +++ b/pillar/api/eve_settings.py @@ -135,8 +135,8 @@ users_schema = { 'type': 'dict', # Keyed by Node ID of the video asset. MongoDB doesn't support using # ObjectIds as key, so we cast them to string instead. - 'keyschema': {'type': 'string'}, - 'valueschema': { + 'keysrules': {'type': 'string'}, + 'valuesrules': { 'type': 'dict', 'schema': { 'progress_in_sec': {'type': 'float', 'min': 0}, diff --git a/pillar/api/node_types/__init__.py b/pillar/api/node_types/__init__.py index 4a25eb40..95d02986 100644 --- a/pillar/api/node_types/__init__.py +++ b/pillar/api/node_types/__init__.py @@ -11,12 +11,11 @@ ATTACHMENT_SLUG_REGEX = r'[a-zA-Z0-9_\-]+' attachments_embedded_schema = { 'type': 'dict', - # TODO: will be renamed to 'keyschema' in Cerberus 1.0 - 'keyschema': { + 'keysrules': { 'type': 'string', 'regex': '^%s$' % ATTACHMENT_SLUG_REGEX, }, - 'valueschema': { + 'valuesrules': { 'type': 'dict', 'schema': { 'oid': { diff --git a/pillar/web/nodes/attachments.py b/pillar/web/nodes/attachments.py index 321ab9d0..b7369395 100644 --- a/pillar/web/nodes/attachments.py +++ b/pillar/web/nodes/attachments.py @@ -19,10 +19,19 @@ def attachment_form_group_create(schema_prop): def _attachment_build_single_field(schema_prop): + # 'keyschema' was renamed to 'keysrules' in Cerberus 1.3, but our data may still have the old + # names. Same for 'valueschema' and 'valuesrules'. + keysrules = schema_prop.get('keysrules') or schema_prop.get('keyschema') + if keysrules is None: + raise KeyError(f"missing 'keysrules' key in schema {schema_prop}") + valuesrules = schema_prop.get('valuesrules') or schema_prop.get('valueschema') + if valuesrules is None: + raise KeyError(f"missing 'valuesrules' key in schema {schema_prop}") + # Ugly hard-coded schema. fake_schema = { - 'slug': schema_prop['keyschema'], - 'oid': schema_prop['valueschema']['schema']['oid'], + 'slug': keysrules, + 'oid': valuesrules['schema']['oid'], } file_select_form_group = build_file_select_form(fake_schema) return file_select_form_group diff --git a/tests/test_cli/test_maintenance.py b/tests/test_cli/test_maintenance.py index 1df4461c..0d60315f 100644 --- a/tests/test_cli/test_maintenance.py +++ b/tests/test_cli/test_maintenance.py @@ -63,8 +63,8 @@ class UpgradeAttachmentSchemaTest(AbstractPillarTest): "url": {"type": "string"}, "attachments": { "type": "dict", - "keyschema": {"type": "string", "regex": "^[a-zA-Z0-9_ ]+$"}, - "valueschema": { + "keysrules": {"type": "string", "regex": "^[a-zA-Z0-9_ ]+$"}, + "valuesrules": { "type": "dict", "schema": { "oid": {"type": "objectid", "required": True},