From 76c27fcacaa41e6e51b1c2049a0ac03306a0592a Mon Sep 17 00:00:00 2001 From: devs6186 Date: Thu, 19 Feb 2026 02:09:01 +0530 Subject: [PATCH 1/2] [tasks/github] Fix uncommitted UPDATE in update_issue_closed_cntrbs_by_repo_id Fixes #3457 - Replace engine.connect() with engine.begin() so the UPDATE on issues.cntrb_id is actually committed; previously every call was silently rolled back at context-manager exit in SQLAlchemy 2.0 - Wrap the call site in events.py with try/except so a transient DB error here does not abort the entire batch of event collection Signed-off-by: devs6186 Signed-off-by: Adrian Edwards --- collectoss/application/db/lib.py | 5 ++++- collectoss/tasks/github/events.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/collectoss/application/db/lib.py b/collectoss/application/db/lib.py index c5394365d..46d7d5926 100644 --- a/collectoss/application/db/lib.py +++ b/collectoss/application/db/lib.py @@ -546,7 +546,10 @@ def update_issue_closed_cntrbs_by_repo_id(repo_id): ) if update_data: - with engine.connect() as connection: + # engine.begin() auto-commits (or rolls back on exception). + # engine.connect() does NOT auto-commit, so the UPDATE was previously + # silently rolled back on every call (issue #3457). + with engine.begin() as connection: update_stmt = s.text(""" UPDATE issues SET cntrb_id = :cntrb_id diff --git a/collectoss/tasks/github/events.py b/collectoss/tasks/github/events.py index 24b1e42ff..0d2ba905e 100644 --- a/collectoss/tasks/github/events.py +++ b/collectoss/tasks/github/events.py @@ -167,7 +167,10 @@ def _process_events(self, events, repo_id): self._process_issue_events(issue_events, repo_id) self._process_pr_events(pr_events, repo_id) - update_issue_closed_cntrbs_by_repo_id(repo_id) + try: + update_issue_closed_cntrbs_by_repo_id(repo_id) + except Exception as e: + self._logger.error(f"{self.repo_identifier} - {self.task_name}: Failed to update issue closed contributors: {e}") def _process_issue_events(self, issue_events, repo_id): From a14c52d4880b1ec83de7888bc2739b33524b44c4 Mon Sep 17 00:00:00 2001 From: Adrian Edwards Date: Mon, 16 Mar 2026 16:41:27 -0400 Subject: [PATCH 2/2] find and replace engine.connect() with engine.begin() in places we actually perform updates to data Signed-off-by: Adrian Edwards --- collectoss/application/cli/collection.py | 2 +- collectoss/application/cli/github.py | 2 +- collectoss/tasks/data_analysis/insight_worker/tasks.py | 10 +++++----- collectoss/tasks/github/events.py | 4 ++-- collectoss/tasks/github/messages.py | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/collectoss/application/cli/collection.py b/collectoss/application/cli/collection.py index 48a0090eb..251677854 100644 --- a/collectoss/application/cli/collection.py +++ b/collectoss/application/cli/collection.py @@ -201,7 +201,7 @@ def repo_reset(ctx): """ Refresh repo collection to force data collection """ - with ctx.obj.engine.connect() as connection: + with ctx.obj.engine.begin() as connection: connection.execute(s.sql.text(""" UPDATE operations.collection_status SET core_status='Pending',core_task_id = NULL, core_data_last_collected = NULL; diff --git a/collectoss/application/cli/github.py b/collectoss/application/cli/github.py index e3b8f75a2..98995458d 100644 --- a/collectoss/application/cli/github.py +++ b/collectoss/application/cli/github.py @@ -26,7 +26,7 @@ def update_api_key(): Get the ratelimit of Github API keys """ - with DatabaseEngine() as engine, engine.connect() as connection: + with DatabaseEngine() as engine, engine.begin() as connection: get_api_keys_sql = s.sql.text( """ diff --git a/collectoss/tasks/data_analysis/insight_worker/tasks.py b/collectoss/tasks/data_analysis/insight_worker/tasks.py index 123407c58..134293b89 100644 --- a/collectoss/tasks/data_analysis/insight_worker/tasks.py +++ b/collectoss/tasks/data_analysis/insight_worker/tasks.py @@ -128,7 +128,7 @@ def insight_model(repo_git: str,logger,engine) -> None: AND repo_insights.ri_field = to_delete.ri_field """) - with engine.connect() as conn: + with engine.begin() as conn: result = conn.execute(delete_points_SQL, parameters=dict(repo_id=repo_id, min_date=min_date)) # get table values to check for dupes later on @@ -561,7 +561,7 @@ def clear_insights(repo_id, new_endpoint, new_field, logger): AND ri_field = '{}' """.format(repo_id, new_endpoint, new_field) try: - with engine.connect() as conn: + with engine.begin() as conn: result = conn.execute(deleteSQL) except Exception as e: logger.info("Error occured deleting insight slot: {}".format(e)) @@ -579,7 +579,7 @@ def clear_insights(repo_id, new_endpoint, new_field, logger): AND ri_field = '{}' """.format(repo_id, new_endpoint, new_field) try: - with engine.connect() as conn: + with engine.begin() as conn: result = conn.execute(deleteSQL) except Exception as e: logger.info("Error occured deleting insight slot: {}".format(e)) @@ -622,7 +622,7 @@ def clear_insight(repo_id, new_score, new_metric, new_field, logger): AND ri_field = '{}' """.format(record['repo_id'], record['ri_metric'], record['ri_field']) try: - with engine.connect() as conn: + with engine.begin() as conn: result = conn.execute(deleteSQL) except Exception as e: logger.info("Error occured deleting insight slot: {}".format(e)) @@ -676,7 +676,7 @@ def clear_insight(repo_id, new_score, new_metric, new_field, logger): AND ri_metric = '{}' """.format(insight['repo_id'], insight['ri_metric']) try: - with engine.connect() as conn: + with engine.begin() as conn: result = conn.execute(deleteSQL) except Exception as e: logger.info("Error occured deleting insight slot: {}".format(e)) diff --git a/collectoss/tasks/github/events.py b/collectoss/tasks/github/events.py index 0d2ba905e..ff14d4393 100644 --- a/collectoss/tasks/github/events.py +++ b/collectoss/tasks/github/events.py @@ -287,7 +287,7 @@ def _collect_and_process_issue_events(self, owner, repo, repo_id, key_auth, sinc engine = get_engine() - with engine.connect() as connection: + with engine.begin() as connection: if since: # TODO: Remove src id if it ends up not being needed @@ -352,7 +352,7 @@ def _collect_and_process_pr_events(self, owner, repo, repo_id, key_auth, since): engine = get_engine() - with engine.connect() as connection: + with engine.begin() as connection: if since: query = text(f""" diff --git a/collectoss/tasks/github/messages.py b/collectoss/tasks/github/messages.py index 342eeb2ca..c197ec069 100644 --- a/collectoss/tasks/github/messages.py +++ b/collectoss/tasks/github/messages.py @@ -93,7 +93,7 @@ def process_large_issue_and_pr_message_collection(repo_id, repo_git: str, logger engine = get_engine() - with engine.connect() as connection: + with engine.begin() as connection: if since: query = text(f"""