Skip to content

fix: preserve nested report template paths - #590

Merged
fdosani merged 2 commits into
capitalone:mainfrom
Thanatos9404:fix/nested-report-templates
Oct 25, 2026
Merged

fdosani merged 2 commits into
capitalone:mainfrom
Thanatos9404:fix/nested-report-templates

Conversation

@Thanatos9404

@Thanatos9404 Thanatos9404 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Nested relative report templates can fail to load or silently select a same-named template at the root. _resolve_template_path() returns native backslashes on Windows, which Jinja rejects, and its extension fallbacks return only the basename, dropping the subdirectory. A folder named after a template, such as summary/ next to summary.j2, also matched the exact-name check, so render("summary") failed instead of loading summary.j2.

Return forward-slash relative names for Jinja, retain the full relative path when adding or removing .j2, and match only files. A name that matches nothing but a folder now raises the documented FileNotFoundError. Relative names still resolve against datacompy's bundled templates directory, and exact-filename precedence and absolute-path handling remain the same. Includes continue to resolve from that template root, and parent traversal remains rejected by Jinja.

For example, render("custom/summary/report", value=42) now loads datacompy/templates/custom/summary/report.j2, even when datacompy/templates/report.j2 also exists. Nested templates with their exact extension also work on Windows.

Validation on Windows, Python 3.12:

  • Eight affected cases fail on unmodified main; the parent-traversal compatibility test passes. After the fix, all 39 base-module tests pass.
  • Full available suite with PYTHONUTF8=1: 752 passed, 18 skipped, no failures.
  • Default cp1252 mode: 747 passed, 18 skipped, five failures. Those UTF-8 decoding assertions also fail on unmodified main; the existing nested-path assertion now passes.
  • Repository Ruff lint and format checks and changed-file pre-commit hooks pass.
  • Mypy on datacompy/base.py and datacompy/report.py, including imported modules, reports the same 164 diagnostic messages as clean main.
  • Spark and Snowflake optional dependencies are absent locally; live backend validation is not claimed.

No dependencies or public API changes are introduced. This is independent of the HTML charset and Unicode table-width fixes in #588 and #589.

@Thanatos9404
Thanatos9404 requested review from a team as code owners October 13, 2026 17:45
@fdosani
fdosani force-pushed the fix/nested-report-templates branch from 7b0bece to 5944321 Compare October 18, 2026 14:01

@fdosani fdosani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@fdosani
fdosani force-pushed the fix/nested-report-templates branch from 5944321 to 4503a2d Compare October 22, 2026 11:39
@fdosani
fdosani enabled auto-merge (squash) October 22, 2026 11:40
@fdosani fdosani closed this Oct 23, 2026
auto-merge was automatically disabled October 23, 2026 14:31

Pull request was closed

@fdosani fdosani reopened this Oct 23, 2026
@fdosani

fdosani commented Oct 23, 2026

Copy link
Copy Markdown
Member

@Thanatos9404 can you redo the CLA please. Something is wonky with it.

A folder of partials is often named after the template that includes
them, such as summary/ next to summary.j2. The exact name matched the
folder because only existence was checked, so render("summary") passed
the folder to Jinja and failed instead of falling back to summary.j2.

Match only files. A name that matches nothing but a folder now raises
the documented FileNotFoundError.
@fdosani
fdosani force-pushed the fix/nested-report-templates branch from 4503a2d to abe1d8b Compare October 25, 2026 09:34
@Thanatos9404

Copy link
Copy Markdown
Contributor Author

Thanks for rebasing it. The CLA check now reports signed on the new head, so it should be clear once the Spark jobs finish.

@fdosani
fdosani merged commit db10461 into capitalone:main Oct 25, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants