Skip to content

fix(tags): keep user-set tags when creating a finding under product tag inheritance#15097

Merged
rossops merged 1 commit into
DefectDojo:bugfixfrom
valentijnscholten:fix/finding-tag-inheritance-overwrite
Jun 29, 2026
Merged

fix(tags): keep user-set tags when creating a finding under product tag inheritance#15097
rossops merged 1 commit into
DefectDojo:bugfixfrom
valentijnscholten:fix/finding-tag-inheritance-overwrite

Conversation

@valentijnscholten

@valentijnscholten valentijnscholten commented Jun 26, 2026

Copy link
Copy Markdown
Member

Fixes #15092

Problem

When a product has tag inheritance enabled, creating a finding with its own tag via the UI ("add finding" flow) silently drops the user's tag — only the inherited product tags survive. Editing the finding afterwards and adding a tag works, which is what made the loss look specific to creation.

Reproduced exactly:

flow result
create with pre-save tag (finding.tags = [...]; finding.save()) ['producttag'] — user tag gone
add tag after save (edit flow) ['myrandomtag', 'producttag']
inheritance off ✅ user tag survives

Root cause — signal-handler ordering

The post_save dispatch order for Finding is:

  1. imagekit → 2. watson → 3. dojo.tags.signals.inherit_tags_on_instance → 4. tagulous's flush (PostSaveHandler)

Tagulous holds tags assigned to an unsaved instance in an in-memory manager and only writes them to the through table from its own post_save handler, which is registered in tagulous' AppConfig.ready(). Because "dojo" precedes "tagulous" in INSTALLED_APPS, dojo's inheritance handler runs first: reading instance.tags on the freshly-saved row loads an empty, DB-backed manager and discards the pending pre-save tags before tagulous can persist them.

Fix

Before computing/merging inherited tags, flush the instance's own tag fields (tagulous manager.post_save_handler()) so the user's tags are committed first. This makes inheritance independent of signal-handler ordering — findings created with or without their own tags now end up correct.

  • dojo/tags/signals.py — new _flush_pending_tag_fields() helper, called at the top of auto_inherit_product_tags().
  • unittests/test_tag_inheritance.py — two regression tests (create-with-own-tag, create-without-tag). The first fails without the fix and passes with it.

Testing

  • Reproduced the bug and validated the fix in a running stack (both cases correct).
  • test_tag_inheritance (39), test_tags (26), test_tag_inheritance_perf (24) — all green.

…ag inheritance

When a product has tag inheritance enabled, creating a finding with its own
tags via the UI ('add finding' flow: finding.tags = [...]; finding.save())
silently dropped the user's tags — only the inherited product tags survived.
Editing the finding afterwards worked, confirming the loss was on create.

Root cause is signal-handler ordering. tagulous holds tags assigned to an
unsaved instance in an in-memory manager and only writes them from its own
post_save handler, registered in tagulous' AppConfig.ready(). Because 'dojo'
precedes 'tagulous' in INSTALLED_APPS, dojo's inheritance post_save handler
runs first; reading instance.tags on the freshly-saved row loads an empty,
DB-backed manager and discards the pending pre-save tags before tagulous can
persist them.

Fix: before computing/merging inherited tags, flush the instance's own
tag fields (tagulous manager.post_save_handler()) so the user's tags are
committed first. This makes inheritance independent of signal-handler
ordering. Findings created without own tags still inherit correctly.

Fixes DefectDojo#15092
@valentijnscholten valentijnscholten added this to the 3.0.200 milestone Jun 27, 2026
@valentijnscholten valentijnscholten marked this pull request as ready for review June 27, 2026 07:49

@mtesauro mtesauro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved

@rossops rossops merged commit b84ff1f into DefectDojo:bugfix Jun 29, 2026
147 checks passed
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.

6 participants