Skip to content

Commit

Permalink
field_manager does not writes to a non list target field if extend_ta…
Browse files Browse the repository at this point in the history
…rget_list (#616)

* update changelog
* add testcases
* add case for single source field to existing target field
  • Loading branch information
ekneg54 authored Jun 21, 2024
1 parent e8fcf3a commit a60bed5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This release limits the maximum python version to `3.12.3` because of the issue
### Bugfix

* fixes a bug where it could happen that a config value could be overwritten by a default in a later configuration in a multi source config scenario
* fixes a bug in the `field_manager` where extending a non list target leads to a processing failure

## 12.0.0

Expand Down
8 changes: 5 additions & 3 deletions logprep/processor/field_manager/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ def _write_to_single_target(self, args, extend_target_list, overwrite_target, ru
add_and_overwrite(event, target_field, source_fields_values)
return

case State(
extend=True, overwrite=False, single_source_element=False, target_is_list=False
):
case State(extend=True, overwrite=False, target_is_list=False, target_is_none=True):
add_and_overwrite(event, target_field, source_fields_values)
return

case State(extend=True, overwrite=False, target_is_list=False):
source_fields_values = [target_field_value, *source_fields_values]
add_and_overwrite(event, target_field, source_fields_values)
return
Expand Down
59 changes: 56 additions & 3 deletions tests/unit/processor/field_manager/test_field_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@
"delete_source_fields": True,
},
},
{
"message": "This is a message",
},
{"message": "This is a message"},
{"new_field": ["This is a message"]},
),
(
Expand Down Expand Up @@ -113,6 +111,25 @@
},
{"new_field": ["value1", "value2", "value3"]},
),
(
"moves multiple fields and replaces existing target field with list including the existing value",
{
"filter": "field1 OR field2 OR field3",
"field_manager": {
"source_fields": ["field1", "field2", "field3"],
"target_field": "new_field",
"extend_target_list": True,
"delete_source_fields": True,
},
},
{
"field1": "value1",
"field2": "value2",
"field3": "value3",
"new_field": "i exist",
},
{"new_field": ["i exist", "value1", "value2", "value3"]},
),
(
"moves multiple fields and writes them to a existing list",
{
Expand Down Expand Up @@ -436,6 +453,42 @@
{"existing_list": ["hello", "world"], "foo": "bar", "test": "value"},
{"existing_list": ["hello", "world", "bar", "value"], "foo": "bar", "test": "value"},
),
(
"Convert existing target to list",
{
"filter": "message",
"field_manager": {
"source_fields": ["message"],
"target_field": "new_field",
"extend_target_list": True,
},
},
{"message": "Value B", "new_field": "Value A"},
{"message": "Value B", "new_field": ["Value A", "Value B"]},
),
(
"Convert existing target to list with multiple source fields",
{
"filter": "field1 OR field2 OR field3",
"field_manager": {
"source_fields": ["field1", "field2", "field3"],
"target_field": "new_field",
"extend_target_list": True,
},
},
{
"field1": "Value B",
"field2": "Value C",
"field3": "Value D",
"new_field": "Value A",
},
{
"field1": "Value B",
"field2": "Value C",
"field3": "Value D",
"new_field": ["Value A", "Value B", "Value C", "Value D"],
},
),
]

failure_test_cases = [
Expand Down

0 comments on commit a60bed5

Please sign in to comment.