Skip to content

fix(jira): close deleted findings#15050

Open
samiat4911 wants to merge 2 commits into
DefectDojo:devfrom
samiat4911:fix/jira-close-deleted-findings
Open

fix(jira): close deleted findings#15050
samiat4911 wants to merge 2 commits into
DefectDojo:devfrom
samiat4911:fix/jira-close-deleted-findings

Conversation

@samiat4911

Copy link
Copy Markdown
Contributor

Description

Fixes a Jira synchronization bug where deleting a Finding in DefectDojo did not close the linked Jira issue.

This PR updates the Finding delete flow so that:

  • A linked Jira issue is closed during finding_pre_delete.
  • Jira closure is skipped when the linked Jira issue is reassigned to a new duplicate-cluster original.
  • Local Jira issue records can be reassigned when deleting an original Finding that has duplicates.

Key implementation added:

if instance.has_jira_issue and not getattr(instance, "_skip_jira_close_on_delete", False):
    jira_services.close_issue_for_deleted_finding(instance)

When a deleted original Finding has a duplicate cluster and a new original is selected, the Jira issue is moved instead of closed:

new_original = reconfigure_duplicate_cluster(instance, duplicate_cluster)
jira_issue = jira_services.get_issue(instance)
if new_original and jira_issue:
    jira_services.reassign_issue_to_finding(jira_issue, new_original)
    instance._skip_jira_close_on_delete = True

The Jira helper now closes active linked Jira issues using the configured close transition and updates the local Jira change timestamp after a successful transition.

Test results
Added unit coverage in unittests/test_jira_helper.py for:

  • Closing an active linked Jira issue before deleting a Finding.
  • Reassigning a local Jira issue record to another Finding.
  • Calling Jira close logic from finding_pre_delete.
  • Skipping Jira close after reassigning the Jira issue to a new duplicate-cluster original.

Tested locally:

python3 manage.py test unittests.test_jira_helper -v 2 --keepdb --no-input
Ran 9 tests
OK

Also ran:

python -m compileall dojo\finding\helper.py dojo\jira\helper.py dojo\jira\services.py unittests\test_jira_helper.py
git diff --check
ruff check

Documentation

No documentation changes were needed because this fixes existing Jira delete behavior and does not add user-facing configuration.

Checklist

This checklist is for your information.

  • Make sure to rebase your PR against the very latest dev.
  • Features/Changes should be submitted against the dev.
  • Bugfixes should be submitted against the bugfix branch.
  • Give a meaningful name to your PR, as it may end up being used in the release notes.
  • Your code is Ruff compliant (see ruff.toml).
  • Your code is python 3.13 compliant.
  • If this is a new feature and not a bug fix, you've included the proper documentation in the docs at https://github.com/DefectDojo/django-DefectDojo/tree/dev/docs as part of this PR.
  • Model changes must include the necessary migrations in the dojo/db_migrations folder.
  • Add applicable tests to the unit tests.
  • Add the proper label to categorize your PR.

@mtesauro

Copy link
Copy Markdown
Contributor

@valentijnscholten Didn't you do something similar recently?

@valentijnscholten

Copy link
Copy Markdown
Member

Yeah, I raised #14567 :-)

@valentijnscholten valentijnscholten left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I think this is a usefule/needed addition. Some improvement areas:

  • currently all pushing to JIRA is guarded by either the user explicitly selecting to push to JIRA in the UI or API request. Or by checking the value of finding_jira_sync or push_all_isues. At first glance the delete feature in this PR doesn't seem to align with that?
  • it could be possible that the new original already has a JIRA issues linked. Can you make sure that scenario is handled correctly (by skipping the reassign)
  • could you add a comment to each JIRA issue that is closed or reassigned?

@samiat4911 samiat4911 force-pushed the fix/jira-close-deleted-findings branch from 2fb57ff to a46a20e Compare June 23, 2026 05:53
@samiat4911

Copy link
Copy Markdown
Contributor Author

hello @valentijnscholten I made an update regarding your feedback. please review thanks :)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants