Skip to content

[FIX] Guard delete_expired_instances against missing tests and GitHub errors - #1301

Open
knowprasad wants to merge 1 commit into
CCExtractor:masterfrom
knowprasad:fix/delete-expired-instances-guards
Open

knowprasad wants to merge 1 commit into
CCExtractor:masterfrom
knowprasad:fix/delete-expired-instances-guards

Conversation

@knowprasad

Copy link
Copy Markdown
Contributor

Please prefix your pull request with one of the following: [FEATURE] [FIX] [IMPROVEMENT].

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.

My familiarity with the project is as follows (check one):

  • I have never used the project.
  • I have used the project briefly.
  • I have used the project extensively, but have not contributed previously.
  • I am an active contributor to the project.

Problem

In mod_ci/controllers.py, delete_expired_instances() can fail to delete timed-out GCP VMs and abort cleanup for subsequent VMs in two cases:

  1. Missing Test row (test is None): delete_expired_instances() inserts a TestProgress row for test_id without checking whether Test.query.filter(Test.id == test_id).first() returned None. With foreign keys enforced, safe_db_commit() fails and skips deleting the orphaned VM via continue; without foreign key enforcement, repository.get_commit(test.commit) raises AttributeError and aborts the loop.
  2. GitHub API error during status notification: repository.get_commit(test.commit) is called unguarded before delete_instance_with_tracking(). A GithubException aborts delete_expired_instances() before the expired VM is deleted and stops cleanup of any remaining expired VMs.

Fix

  • Extracted _notify_expired_test_on_github() in mod_ci/controllers.py to wrap repository.get_commit(), url_for(), and update_status_on_github() in try...except so GitHub failures are logged without preventing VM deletion.
  • In delete_expired_instances(), skip TestProgress insertion and GitHub status notification (logging a warning) when test is None, and proceed directly to delete_instance_with_tracking(). Existing if not safe_db_commit(...): continue behavior when test exists is preserved.
  • Added 2 unit tests in tests/test_ci/test_controllers.py:
    • test_delete_expired_instances_missing_test_still_deletes_vm
    • test_delete_expired_instances_github_error_still_deletes_vm

Verification

  • Verified both new tests fail on master before the fix (GithubException aborting before VM deletion; AssertionError skipping 'linux-99999' deletion) and pass after the fix.
  • nose2 tests.test_ci.test_controllers.TestControllers.test_delete_expired_instances ... (5 tests): OK.
  • nose2 tests.test_ci.test_comparison tests.test_ci.test_markdown tests.test_ci.test_negative_runtime_fix (29 tests): OK.
  • Linters (dodgy, isort . --check-only, pydocstyle --config=./.pydocstylerc, mypy ., pycodestyle ./ --config=./.pycodestylerc): all exit 0.
  • pytest tests/test_ci/ on Windows: 240 passed, 11 pre-existing Windows-only failures (4 test_cron_job_* needing fcntl, 7 blocked_users tests needing /dev/urandom secret_key tracked in #1265).

@sonarqubecloud

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant