@@ -307,6 +307,45 @@ def test_mixed_products_only_flagged_product_propagates(self):
307307 self .assertEqual (sorted (t .name for t in eng_with .tags .all ()), ["inherit-me" ])
308308 self .assertEqual (list (eng_without .tags .all ()), [])
309309
310+ def test_finding_created_with_own_tag_keeps_it_and_inherits (self ):
311+ """
312+ Regression test for #15092.
313+
314+ Assigning tags to an unsaved finding and then saving it (the UI
315+ "add finding" flow: ``finding.tags = [...]; finding.save()``) must keep
316+ the user's own tags *and* merge the inherited product tags. Previously
317+ the inheritance post_save handler ran before tagulous persisted the
318+ pre-save tags and silently dropped them.
319+ """
320+ product = self .create_product ("Inherit On Create" , tags = ["product-tag" ])
321+ product .enable_product_tag_inheritance = True
322+ product .save ()
323+ engagement = self .create_engagement ("Eng" , product )
324+ test = self .create_test (engagement = engagement , scan_type = "ZAP Scan" )
325+
326+ finding = Finding (test = test , title = "With own tag" , severity = "Medium" , reporter = self .get_test_admin ())
327+ finding .tags = ["my-own-tag" ]
328+ finding .save ()
329+ finding .refresh_from_db ()
330+
331+ self .assertEqual (sorted (t .name for t in finding .tags .all ()), ["my-own-tag" , "product-tag" ])
332+ self .assertEqual ([t .name for t in finding .inherited_tags .all ()], ["product-tag" ])
333+
334+ def test_finding_created_without_own_tag_still_inherits (self ):
335+ """A finding created with no tags must still receive the product's inherited tags (#15092 guard)."""
336+ product = self .create_product ("Inherit No Own Tag" , tags = ["product-tag" ])
337+ product .enable_product_tag_inheritance = True
338+ product .save ()
339+ engagement = self .create_engagement ("Eng" , product )
340+ test = self .create_test (engagement = engagement , scan_type = "ZAP Scan" )
341+
342+ finding = Finding (test = test , title = "No own tag" , severity = "Medium" , reporter = self .get_test_admin ())
343+ finding .save ()
344+ finding .refresh_from_db ()
345+
346+ self .assertEqual ([t .name for t in finding .tags .all ()], ["product-tag" ])
347+ self .assertEqual ([t .name for t in finding .inherited_tags .all ()], ["product-tag" ])
348+
310349
311350# ---------------------------------------------------------------------------
312351# Integration tests — endpoint inheritance (v2 only)
0 commit comments