Skip to content

Commit

Permalink
given an None full_schema, do not fail.
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Nov 29, 2023
1 parent 7fdfebd commit 2fe34c7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/collective/elastic/ingest/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,20 @@ 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:
fields = config["__fields"]
for field in fields:
if field["name"] in content:
del content[field["name"]]
del section[config["name"]]


ACTION_FUNCTIONS["full_remove"] = action_full_remove
Expand Down
21 changes: 21 additions & 0 deletions src/collective/elastic/ingest/preprocessing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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"}

0 comments on commit 2fe34c7

Please sign in to comment.