diff --git a/CHANGELOG.md b/CHANGELOG.md index ea4319b25..16796df86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ### Improvements ### Bugfix +* Fix writing time measurements into the event after the deleter has deleted the event. The bug only +happened when the `metrics.measure_time.append_to_event` configuration was set to `true`. + ## v6.8.0 ### Features diff --git a/logprep/util/time_measurement.py b/logprep/util/time_measurement.py index fe7bd8290..532a27d00 100644 --- a/logprep/util/time_measurement.py +++ b/logprep/util/time_measurement.py @@ -45,6 +45,8 @@ def inner(*args, **kwargs): # nosemgrep return func(*args, **kwargs) def add_processing_times_to_event(event, processing_time, caller, name): # nosemgrep + if caller.name == "deleter" and not event: + return if not event.get("processing_times"): event["processing_times"] = {} if name is None: diff --git a/tests/unit/util/test_time_measurement.py b/tests/unit/util/test_time_measurement.py index f0bed3294..2ce2a3b2d 100644 --- a/tests/unit/util/test_time_measurement.py +++ b/tests/unit/util/test_time_measurement.py @@ -10,6 +10,7 @@ class TestTimeMeasurement: def setup_method(self): self.event = {"test_key": "test_val"} + self.name = "TestTimeMeasurement" @TimeMeasurement.measure_time("test") def dummy_method(self, event): # pylint: disable=unused-argument @@ -34,6 +35,16 @@ def test_time_measurement_decorator_appends_processing_times_to_event(self): assert timestamp is not None assert isinstance(timestamp, float) + def test_time_measurement_decorator_does_not_append_processing_time_to_event_after_deleter_deletes_event( + self, + ): + TimeMeasurement.TIME_MEASUREMENT_ENABLED = True + TimeMeasurement.APPEND_TO_EVENT = True + self.name = "deleter" # setting the caller name to deleter, simulates a call of the deleter + event = {} + self.dummy_method(event) + assert not event + def test_deactivated_decorator_does_not_do_a_thing(self): TimeMeasurement.TIME_MEASUREMENT_ENABLED = False TimeMeasurement.APPEND_TO_EVENT = False