fix(findings): normalize blank components to NULL (SC-13073)#15038
Open
Maffooch wants to merge 2 commits into
Open
fix(findings): normalize blank components to NULL (SC-13073)#15038Maffooch wants to merge 2 commits into
Maffooch wants to merge 2 commits into
Conversation
Findings could store an empty string for component_name/component_version depending on the write path (the edit form already stores NULL, but the API and importers do not). Because the database treats "" as distinct from NULL, the All Components view grouped these into a separate "None" row. Finding.save() now normalizes blank (empty or whitespace-only) component values to NULL, and a data migration converts existing empty-string values so component-less findings group together. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment on lines
+18
to
+26
| blank_name = Finding.objects.annotate( | ||
| component_name_trimmed=Trim("component_name"), | ||
| ).filter(Q(component_name="") | Q(component_name_trimmed="")) | ||
| name_updated = blank_name.update(component_name=None) | ||
|
|
||
| blank_version = Finding.objects.annotate( | ||
| component_version_trimmed=Trim("component_version"), | ||
| ).filter(Q(component_version="") | Q(component_version_trimmed="")) | ||
| version_updated = blank_version.update(component_version=None) |
Member
There was a problem hiding this comment.
could we do some chunking with batch_size here to avoid it having getting/updating "millions" of findings at a time?
Process blank component_name/component_version rows in bounded seek-paged chunks instead of two unbounded UPDATE statements, so the migration never locks/writes "millions" of findings at once. Mirrors the page_size idiom in 0201_populate_finding_sla_expiration_date. Addresses review feedback on PR #15038. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
valentijnscholten
approved these changes
Jun 18, 2026
valentijnscholten
left a comment
Member
There was a problem hiding this comment.
hmmm my initial thought was that just using batch_size= on the update would do it?
Contributor
Author
|
Now we get logging too! A "hung" migration is nerve racking |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes SC-13073 — removing a Finding's component created a separate "None" component group.
The All Components view groups findings by
component_name. Because the database treats an empty string ("") as distinct fromNULL, findings whose component was stored as""(via the API or importers) appeared as a second "None" row, separate from findings with aNULLcomponent.Note: the finding edit form already stores
NULL(Django setsempty_value=Nonefornull=TrueCharFields), so the inconsistency came from other write paths.Changes
Finding.save()now normalizes blank (empty or whitespace-only)component_name/component_versiontoNULL, so every write path is consistent.0269_normalize_blank_finding_componentsconverts existing empty-string component values toNULLon upgrade.docs/content/releases/os_upgrading/3.1.md.Testing
unittests.test_finding_model.TestFindingComponentNormalization— new (verified red→green; empty/whitespace → NULL, real values preserved, NULL + "" findings group together).unittests.test_edit_finding_endpoints.TestEditFindingComponentView— new (clearing components via the edit view stores NULL).test_finding_model→ 67 OK,test_edit_finding_endpoints→ 14 OK.🤖 Generated with Claude Code