From 3abcb42b1182673e3276b34dc866e0c93914d0cd Mon Sep 17 00:00:00 2001 From: Nora Zinaeddin Date: Thu, 16 May 2024 11:17:32 +0200 Subject: [PATCH] Make sure the correct number of runs is displayed In some rare cases, when an error occurs while deleting runs, the number of runs to be deleted is deducted from the "Number of runs" value displayed in the "Products" view, even though some runs do not get deleted. For this reason, the number of runs could go negative upon the next run deletion. This change is to fix this issue. --- .../codechecker_server/api/report_server.py | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/web/server/codechecker_server/api/report_server.py b/web/server/codechecker_server/api/report_server.py index 41f2db1136..85655b742e 100644 --- a/web/server/codechecker_server/api/report_server.py +++ b/web/server/codechecker_server/api/report_server.py @@ -3424,10 +3424,27 @@ def removeRun(self, run_id, run_filter): # cascades and such. Deleting runs in separate transactions don't # exceed a potential statement timeout threshold in a DBMS. runs = [] + deleted_run_cnt = 0 + for run in q.all(): - runs.append(run.name) - session.delete(run) - session.commit() + try: + runs.append(run.name) + session.delete(run) + session.commit() + deleted_run_cnt += 1 + except Exception as e: + # TODO: Display alert on the GUI if there's an exception + # TODO: Catch SQLAlchemyError instead of generic + # exception once it is confirmed that the exception is + # due to a large run deletion timeout based on server + # log warnings + # This exception is handled silently because it is + # expected to never occur, but there have been some rare + # cases where it occurred due to underlying reasons. + # Handling it silently ensures that the Number of runs + # counter is not affected by the exception. + LOG.warning(f"Suppressed an exception while " + f"deleting run {run.name}. Error: {e}") session.close() @@ -3436,7 +3453,7 @@ def removeRun(self, run_id, run_filter): # Decrement the number of runs but do not update the latest storage # date. - self._set_run_data_for_curr_product(-1 * len(runs)) + self._set_run_data_for_curr_product(-1 * deleted_run_cnt) # Remove unused comments and unused analysis info from the database. # Originally db_cleanup.remove_unused_data() was used here which