Repository navigation
fix(454): coerce document_files keys and paths in the gallery - #455
Conversation
html.escape requires str. Integer keys or paths (common when doc_id comes off a DataFrame column) raised AttributeError and generate_report returned success=False with no page. Coerce both sides before escape so int 1001 and "1001" also agree as the gallery key.
digalaviz
left a comment
There was a problem hiding this comment.
Reviewed at 651087a. Thank you for this. The four str() calls are in the right places, and
removing any one of them fails its own test. Two gaps remain before this closes #454.
Requested changes:
- The tests use only a Python
int, so they pass for code that coerces onlyint. With that
narrower rule, annp.int64key (what indexing an integer DataFrame column gives) still makes
generate_reportreturnsuccess=Falsein both modes, and apathlib.Pathpath still makes
generate_document_galleryraise. Please add a test with annp.int64key and aPathpath, in
image and PDF mode. - The collision decision is stated but not asserted. #454 asks for it not to be left implied.
With{1001: "a.png", "1001": "b.png"}the gallery renders two items with the same label, and in
PDF mode two items withdata-doc-id="1001"; the report's script then keeps only one of them.
Please either reject a collision after conversion, or keep the current behaviour and add a test
that asserts it. The code comment "str() makes int 1001 and '1001' agree as the gallery key"
should match whichever you choose.
Also worth changing:
- All four tests call
generate_document_gallerydirectly. One test throughgenerate_reportwith
{1001: path}that assertsresult.successwould cover the symptom #454 reports. - The PR body says the CHANGELOG sentence "stays", but that sentence is not on
dev, so there is
nothing to keep. An entry under[Unreleased]### Fixedfor this change would be enough.
Dependency on #464: on dev alone, a numeric doc_id still fails generate_report in the
non-matches table, which #464 fixes. With #464 merged, this PR works end to end, and the gallery
ids agree with the embedded doc_ids. It merges cleanly with #464 and with #466.
|
@digalaviz Addressed in f2df861: added an np.int64 key + Path value test in image and PDF mode, kept the current collision behaviour and asserted it (both entries preserved, in order, in both modes) with the code comment updated to match, added a generate_report test with {1001: path} asserting success, and moved the CHANGELOG entry under [Unreleased] Fixed. Branch is merged with current dev. |
…odes Assert generate_report succeeds in image and pdf modes when document_files uses an np.int64 key and a Path value, addressing reviewer feedback on awslabs#454.
Security Scan ResultsASH Security Scan Report
Scan Metadata
SummaryScanner ResultsThe table below shows findings by scanner, with status based on severity thresholds and dependencies:
Top 4 HotspotsFiles with the highest number of security findings:
Detailed FindingsShow 7 actionable findingsFinding 1: SECRET-HEX-HIGH-ENTROPY-STRING
Description: Code Snippet: Finding 2: B310
Description: Code Snippet: Finding 3: B108
Description: Code Snippet: Finding 4: B307
Description: Code Snippet: Finding 5: B307
Description: Code Snippet: Finding 6: B102
Description: Code Snippet: Finding 7: B310
Description: Code Snippet: Report generated by Automated Security Helper (ASH) at 2026-11-08T21:11:45+00:00 |
|
Reviewed at One non-blocking suggestion: the |
digalaviz
left a comment
There was a problem hiding this comment.
Approving at a6486f4, per the comment above.
Why
generate_document_gallerypassesdocument_fileskeys and paths straight tohtml.escape. When either side is a non-str(typical oncedoc_idcomes off an integer DataFrame column),html.escaperaisesAttributeError: 'int' object has no attribute 'replace'.generate_reportcatches that and returnssuccess=Falsewith no page written — silent if the caller ignores.success.Measured on current
devthe same way #454 describes for 1.0.1:{1001: "scan.png"}and{"doc-1": 1001}both blow up in image and PDF modes.What changed
In
SectionGenerator.generate_document_gallery, coerce both the key and the path withstr()before everyhtml.escapecall (image branch and PDF branch). Same shape as thedoc_idcoercion_load_individual_resultsgained for 1.0.1.Deliberate collision: after conversion, integer
1001and string"1001"are the same gallery key. That matches the filter-side behaviour 1.0.1 already records for JSONLdoc_id, so pairing a document with its page stays consistent across those two surfaces.No CHANGELOG edit: the 1.0.1 sentence that the gallery still requires
strkeys and paths stays until that release notes cycle; this PR is the 2.0.0 fix #454 targets.Scope / blast radius
section_generator.py._copy_files_to_report_dirstill passes keys through untouched (as [BUG]: generate_document_gallery fails silently on a non-str document_files key or path #454 asks).Verification
Removing either
str()makes the matching new test fail with the AttributeError above.Fixes #454