Skip to content

Switch the report writer from the docxtpl fork to docform - #1015

Open
cvas22 wants to merge 2 commits into
GhostManager:masterfrom
cvas22:docform
Open

cvas22 wants to merge 2 commits into
GhostManager:masterfrom
cvas22:docform

Conversation

@cvas22

@cvas22 cvas22 commented Dec 1, 2026 •

Copy link
Copy Markdown

Issue

#1013 (per discussion, opening to a PR for this in the thread).

Description of the Change

Swaps the report writer off the GhostManager fork of python-docx-template and onto docform, a maintained fork of the same project published on PyPI. Full disclosure, I maintain docform.

The reportwriter only touches the public API (DocxTemplate, RichText, new_subdoc), so this is an import swap plus the requirements pin: docform[subdoc]==1.1.0 instead of the git pin, and from docform import ... in the three reportwriter modules. I left your forked python-docx alone; docform's python-docx requirement is unpinned, so your fork still satisfies it and nothing gets double-installed. I also added "docform." to ReportSandboxedEnvironment._blocked_object_module_prefixes so the render sandbox keeps blocking the templating library's internals now that they live under a different module.

Alternate Designs

Keep carrying the fork. The reason to switch is to stop maintaining a private fork and pick up fixes from a maintained one. docform already made the post-render body swap linear, which looks like what a lot of your fork's perf commits are about, and upstream PR #626 (OOXML font/style order) is in it too.

Possible Drawbacks

docform tracks upstream python-docx-template, so any Ghostwriter-specific behavior in your fork that never went upstream could differ. I diffed your v0.21.0 against upstream: the 37 commits ahead are almost all performance work, plus a couple of header/footer Jinja-detection tweaks. The full reporting suite passes against docform, but if you have templates with unusual Jinja in headers or footers those are the spot worth an eyeball.

Verification Process

Built the CI django image with the docform pin (installs cleanly alongside your python-docx fork), brought up postgres and redis, and ran manage.py test ghostwriter.reporting --exclude-tag=GitHub against docform 1.0.2. 667 tests pass, no failures. The existing reporting tests exercise the DOCX/PPTX export, rich text, templating and footnote paths, which is where docform does the rendering.

Release Notes

Switched the report writer from the docxtpl fork to docform.

@chrismaddalena

Copy link
Copy Markdown
Collaborator

Thanks for putting this together. I’m open to switching to Docform. Could you address two compatibility issues we found with 1.0.2?

  • Drawing IDs. A template with an image in the header and another in the body exported with the same wp:docPr ID on both. Please preserve unique drawing IDs across document parts so header logos and evidence images can coexist safely.
  • Missing table grids. A table without an explicit w:tblGrid currently aborts the export. Please handle the missing grid gracefully so the table is preserved and the report can still export.

Could you publish a release with those fixes and the [large-template rendering fix from Docform #210](cvas22/docform#210), then update this PR to pin that release? That would give us a build to validate against our reporting suite and larger templates.

@cvas22

cvas22 commented Dec 6, 2026 •

Copy link
Copy Markdown
Author

@chrismaddalena thanks for the report, could you confirm if the two issues preexists in the old library (python-docx)?
EDIT: It does. Tracking issue: cvas22/docform#213

@cvas22

cvas22 commented Dec 6, 2026

Copy link
Copy Markdown
Author

Thx for testing. Both are fixed in docform 1.1.0, now on PyPI: header, footer and body images get unique drawing IDs, and tables without a w:tblGrid render normally. It needs Python 3.10+. If anything still looks off with your templates, send me a stripped-down copy.

Use docform[subdoc] from PyPI in place of the GhostManager python-docx-template
fork, and import DocxTemplate/RichText from docform. Add docform. to the render
sandbox's blocked module prefixes. The forked python-docx is left as-is.

This branch has not been deployed

No deployments
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