diff --git a/pipestat/backends/filebackend.py b/pipestat/backends/filebackend.py index 5198edd8..8bd69e28 100644 --- a/pipestat/backends/filebackend.py +++ b/pipestat/backends/filebackend.py @@ -340,6 +340,23 @@ def remove( record_identifier=record_identifier, rm_record=rm_record, ) + # Check if the last remaining attributes are the timestamps + remaining_attributes = list( + self._data[self.pipeline_name][self.pipeline_type][record_identifier].keys() + ) + if ( + len(remaining_attributes) == 2 + and CREATED_TIME in remaining_attributes + and MODIFIED_TIME in remaining_attributes + ): + _LOGGER.info( + f"Last result removed for '{record_identifier}'. " f"Removing the record" + ) + rm_record = True + self.remove_record( + record_identifier=record_identifier, + rm_record=rm_record, + ) with self._data as locked_data: locked_data.write() return True diff --git a/tests/test_pipestat.py b/tests/test_pipestat.py index 07d520eb..95037b98 100644 --- a/tests/test_pipestat.py +++ b/tests/test_pipestat.py @@ -79,7 +79,6 @@ def test_basics( assert status == "running" assert val_name in psm.retrieve(record_identifier=rec_id) psm.remove(record_identifier=rec_id, result_identifier=val_name) - #psm.remove(record_identifier=rec_id) if backend == "file": psm.clear_status(record_identifier=rec_id) status = psm.get_status(record_identifier=rec_id)