Skip to content

fix(metrics): paginate the open findings table on Organization and Asset Tag Counts - #17124

Merged
Maffooch merged 1 commit into
DefectDojo:devfrom
skywalke34:fix/counts-paginate-open-findings
Dec 3, 2026
Merged

Maffooch merged 1 commit into
DefectDojo:devfrom
skywalke34:fix/counts-paginate-open-findings

Conversation

@skywalke34

Copy link
Copy Markdown
Contributor

Description

Organization Counts (/metrics/organization/counts) and Asset Tag Counts (/metrics/asset/tag/counts) end with an " Open Findings" table that lists every open finding in the organization (or tag), all on one page. On a demo instance, for one organization in one month:

Before After
Open findings rows rendered 7,376 25 per page (296 pages)
HTML size 7.2 MB 91 KB
Server time (3 runs, warm) 0.70 – 0.77 s 0.18 – 0.19 s (one 1.0 s outlier)
Page height 492,255 px 3,501 px

Both views (product_type_counts, product_tag_counts) now page all_current_in_pt with the existing get_page_items helper (25 per page, open prefix), ordered by numerical_severity, newest first, with id as a stable tiebreak. Before, it was ordered by severity only, which isn't stable across pages. In the shared pt_counts.html:

  • The shared paging_snippet.html, with a page-size picker, goes under the table.
  • The "No." column continues across pages via start_index.
  • The paging links keep the month/year and product_type/product_tag filters, since the snippet uses url_replace.

The tablesorter-bootstrap class on the table is inert: no script loads tablesorter, and other paginated tables such as view_product_type.html carry it too. So no client-side sort is lost.

Before: row 7,376 at the bottom of a 492,255 px page After: page 2 shows entries 26–50
before after

Test results

  • New unittests/test_counts_open_findings_paging.py (2 tests, one per page). Both fail on current dev, where the table gets an unpaged queryset, and pass with this change. Each checks:
    • Page 1 renders 25 rows numbered from 1.
    • The page-2 link keeps the period and organization/tag filters.
    • Page 2 numbering starts at 26.
  • Existing metrics suites still pass: 23 tests OK in total, 2 pre-existing skips.
  • Live checks: Asset Tag Counts renders, and an invalid page (openpage=abc) returns 200.
  • ruff check (0.16.10) passes.

Documentation

None needed (bug fix).

Checklist

  • Rebased against the latest dev.
  • Submitted against the dev branch.
  • Meaningful PR name.
  • Ruff compliant.
  • Python 3.13 compliant.
  • New feature documentation: n/a, bug fix.
  • Migrations: n/a, no model changes.
  • Unit tests added.
  • Labels and milestone applied.

Generated with Claude Code under the direction of T. Walker (skywalke34) - DefectDojo

…set Tag Counts

product_type_counts and product_tag_counts passed every open finding in the
organization (or tag) to pt_counts.html, which rendered all of them: 7,376
rows and a 7.2 MB page for one organization on a demo instance.

Page the queryset in both views with get_page_items (25 per page, `open`
prefix, ordered by numerical_severity, newest first, id as tiebreak), add
the shared paging snippet under the table, and continue the "No." column
across pages via start_index. The paging links keep the month/year and
organization/tag filters. The same page is now ~0.2 s and 91 KB.

Authored by T. Walker - DefectDojo
@skywalke34 skywalke34 added this to the 3.6.0 milestone Dec 1, 2026
@skywalke34 skywalke34 added bugfix performance performance improvement or bug report labels Dec 1, 2026
@dryrunsecurity

dryrunsecurity Bot commented Dec 1, 2026

Copy link
Copy Markdown

DryRun Security

This pull request contains critical findings where user 'skywalke34' modified sensitive codepaths in 'dojo/templates/dojo/pt_counts.html' and 'dojo/metrics/views.py' without being on the allowed authors list.

🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/pt_counts.html (drs_883b47e2)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/pt_counts.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'skywalke34' (commit f56662f) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/metrics/views.py (drs_980ff199)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/metrics/views.py' matches configured sensitive codepath pattern 'dojo/metrics/*.py' and was modified by 'skywalke34' (commit f56662f) who is not in the allowed authors list.

We've notified @mtesauro.


Comment to provide feedback on these findings.

Report false positive: @dryrunsecurity fp [FINDING ID] [FEEDBACK]
Report low-impact: @dryrunsecurity nit [FINDING ID] [FEEDBACK]

Example: @dryrunsecurity fp drs_90eda195 This code is not user-facing

All finding details can be found in the DryRun Security Dashboard.

@Maffooch Maffooch 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.

Review: #17124 fix(metrics): paginate the open findings table on Organization and Asset Tag Counts

Verdict: approve-with-nits
Head SHA reviewed: f56662f
Profile: code change (two views + shared template + new unit test)
Base / milestone: dev, 3.6.0 (correct)

Gates

  • ruff 0.16.10: all checks passed.
  • CI: 40 of 40 pass.
  • No model, settings or Helm change.

New test vs base

  • unittests.test_counts_open_findings_paging on the PR head: 2 tests OK.
  • With dojo/metrics/views.py and pt_counts.html reverted to origin/dev: both error ('TagulousCastTaggedBaseQuerySet' object has no attribute 'paginator').

Break attempts

  1. Hostile page params. openpage=abc and openpage=999 return 200. openpage_size=abc returns 500 (ValueError) and openpage_size=0 returns 500 (ZeroDivisionError). On dev these params are ignored (200). Same root cause as on #17123: dojo/utils.py:912 returns 500 for page_size=abc / 0 on every paginated page on dev (I reproduced it on /metrics/engineer and /finding/open). Follow-up, not a blocker.
  2. Query count and prefetch on a page. Whole page at page size 25 vs 100: 77 vs 77 (on dev: 76, the extra one is the paginator count). The existing prefetch_related applies to the page slice, so rows add no N+1. No break.
  3. Filter preservation and numbering. Live on a local stack, Organization Counts for an org with 60 findings: 25 rows, the first "No." cell is 1, and the pager hrefs are ?month=12&year=2026&product_type=2&openpage=2. The PR's test also covers Asset Tag Counts and page-2 numbering starting at 26. No break.
  4. Empty organization. A new org with no findings renders 200 with the table header and no pager (paging_snippet.html is gated on paginator.count > 0). The table wrapper is keyed on pt on both dev and the PR, so nothing changes. No break.
  5. Other template uses of all_current_in_pt. In pt_counts.html it appears only in the loop and the new include, with no |length or count that would now read 25. The heading uses pt. No break.
  6. Interaction with #17122 (the same "No." row) and #17125 (the same file): no conflicts. The combined tree passes 35 tests. No break.

Blocking

None.

Nice-to-haves

  • Follow-up issue for the shared get_page_items_and_count size parsing (see attempt 1).
  • The page-size dropdown in paging_snippet.html uses a fixed id="pageSizeDropdown". That is fine here because each counts page has a single pager.

Verified hands-on

Tests on the PR head and with the fix reverted. My edge-case test on the PR and on dev. Live Organization Counts and Asset Tag Counts on the combined tree.

Statically only

Template uses of the context variable.

Could not reproduce

The 7,376-row timings in the description.

@Maffooch
Maffooch added this pull request to the merge queue Dec 3, 2026
Merged via the queue into DefectDojo:dev with commit 9721139 Dec 3, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix performance performance improvement or bug report ui unittests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants