From 2fe34c7f4fe393888607c9188b401531e349728d Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Wed, 29 Nov 2023 14:13:39 +0100 Subject: [PATCH] given an None full_schema, do not fail. --- .../elastic/ingest/preprocessing.py | 4 ++-- .../elastic/ingest/preprocessing_test.py | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/collective/elastic/ingest/preprocessing.py b/src/collective/elastic/ingest/preprocessing.py index 733856e..c06cce4 100644 --- a/src/collective/elastic/ingest/preprocessing.py +++ b/src/collective/elastic/ingest/preprocessing.py @@ -126,12 +126,13 @@ def action_field_remove(content, full_schema, config): def action_full_remove(content, full_schema, config): """remove full behavior or types fields.""" - section = full_schema[config["section"]] if full_schema: + section = full_schema[config["section"]] # we need to cache the fields, because in subsequent calls there is no schema provided fields = section.get(config["name"]) if not fields: return + del section[config["name"]] if "__fields" not in "config": config["__fields"] = fields else: @@ -139,7 +140,6 @@ def action_full_remove(content, full_schema, config): for field in fields: if field["name"] in content: del content[field["name"]] - del section[config["name"]] ACTION_FUNCTIONS["full_remove"] = action_full_remove diff --git a/src/collective/elastic/ingest/preprocessing_test.py b/src/collective/elastic/ingest/preprocessing_test.py index 9896140..fa7ea6e 100644 --- a/src/collective/elastic/ingest/preprocessing_test.py +++ b/src/collective/elastic/ingest/preprocessing_test.py @@ -84,6 +84,15 @@ def test_action_field_remove(): assert root == {"foo": "bar"} assert len(full_schema["behaviors"]["plone.basic"]) == 1 + # on a second call the full_schema might be None + # Nonetheles the field should be removed + root = { + "foo": "bar", + "title": "Foo", + } + preprocessing.action_field_remove(root, None, config) + assert root == {"foo": "bar"} + def test_action_full_remove(): full_schema = { @@ -118,3 +127,15 @@ def test_action_full_remove(): assert root == {"baz": "Baaz", "description": "Bar", "title": "Foo"} assert "plone.categorization" not in full_schema["behaviors"] + + # on a second call the full_schema might be None + # Nonetheles the field should be removed + root = { + "title": "Foo", + "description": "Bar", + "subjects": ["Foo", "Bar"], + "language": "de", + "baz": "Baaz", + } + preprocessing.action_full_remove(root, None, config) + assert root == {"baz": "Baaz", "description": "Bar", "title": "Foo"}