Skip to content

Commit

Permalink
rename _add_one_field_to to _add_field_to for clarity
Browse files Browse the repository at this point in the history
- Simplified function name to better reflect its purpose.
- Updated all instances where the function is invoked to maintain consistency.
  • Loading branch information
dtrai2 committed Nov 13, 2024
1 parent 827b7f4 commit 8405edd
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions logprep/util/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _add_and_not_overwrite_key(sub_dict, key):
return sub_dict.get(key)


def _add_one_field_to(
def _add_field_to(
event: dict,
field: tuple,
rule: "Rule",
Expand Down Expand Up @@ -118,7 +118,7 @@ def _add_one_field_to(
target_parent[target_key].append(content)


def _add_one_field_to_silent_fail(*args, **kwargs) -> None | str:
def _add_field_to_silent_fail(*args, **kwargs) -> None | str:
"""
Adds a field to an object, ignoring the FieldExistsWarning if the field already exists. Is only needed in the
add_batch_to map function. Without this the map would terminate early.
Expand All @@ -136,7 +136,7 @@ def _add_one_field_to_silent_fail(*args, **kwargs) -> None | str:
FieldExistsWarning: If the field already exists, but this warning is caught and ignored.
"""
try:
_add_one_field_to(*args, **kwargs)
_add_field_to(*args, **kwargs)
except FieldExistsWarning as error:
return error.skipped_fields[0]

Expand Down Expand Up @@ -173,12 +173,10 @@ def add_fields_to(
fields = {key: value for key, value in fields.items() if value is not None}
number_fields = len(dict(fields))
if number_fields == 1:
_add_one_field_to(
event, list(fields.items())[0], rule, extends_lists, overwrite_target_field
)
_add_field_to(event, list(fields.items())[0], rule, extends_lists, overwrite_target_field)
return
unsuccessful_targets = map(
_add_one_field_to_silent_fail,
_add_field_to_silent_fail,
itertools.repeat(event, number_fields),
fields.items(),
itertools.repeat(rule, number_fields),
Expand Down

0 comments on commit 8405edd

Please sign in to comment.