Repository navigation
fix(report): support S3 cloud media storage for report and label template loading (#12426) - #12943
Merged
SchrodingersGat merged 9 commits intoOct 13, 2026
Conversation
…late loading (inventree#12426) - Prevent TemplateDoesNotExist when using cloud storage backends (e.g. S3 via django-storages) - Update TemplateUploadMixin.template_name to return relative storage path when local file does not exist on disk - Implement ReportTemplateBase.get_template_content() to load content from storage backend and resolve bucket/location prefix mismatches - Add fallback in ReportTemplateBase.render_as_string() to render from storage content when template loader lookup fails - Register InvenTreeStorageTemplateLoader to allow template snippets to resolve directly from default_storage - Add unit tests in S3ReportTemplateTest covering prefix resolution, remote rendering, and storage template loading
✅ Deploy Preview for inventree-web-pui-preview canceled.
|
matmair
reviewed
Sep 28, 2026
matmair
reviewed
Sep 28, 2026
matmair
reviewed
Sep 28, 2026
matmair
reviewed
Sep 28, 2026
matmair
left a comment
Member
There was a problem hiding this comment.
Interesting approach overall, looks good. Thank you submitting for it.
I have some questions on a part of the patchset, looking forward to getting some insights.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #12943 +/- ##
==========================================
- Coverage 87.28% 87.25% -0.04%
==========================================
Files 1515 1515
Lines 104716 104512 -204
Branches 11902 11743 -159
==========================================
- Hits 91406 91190 -216
- Misses 13243 13259 +16
+ Partials 67 63 -4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
SchrodingersGat
previously requested changes
Sep 29, 2026
Member
|
@xyz-is-best are you ok with a maintainer fixing the nitpicks that we mentioned? This looks good overall and I would love to get this into 1.6.0 |
Member
|
@SchrodingersGat this is ready if we include xyz-is-best#1 in it |
this is unrealstic in a full enviroment; the only reason for this is some very constraint sandbox - which is not our run enviroment
matmair
approved these changes
Oct 12, 2026
Member
|
@xyz-is-best thanks for the contribution! |
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 of Changes
Fixes #12426 by supporting remote cloud storage backends (e.g. AWS S3 or MinIO via
django-storages) when resolving and rendering report and label templates.Root Cause
Previously:
TemplateUploadMixin.template_nameunconditionally prependedsettings.MEDIA_ROOT, which assumes templates are saved to a local disk path. When cloud media storage is active, the file does not exist underMEDIA_ROOT, causingTemplateDoesNotExistduring template lookup.storage.location = 'inventree-server'), causing relative path mismatches when looking up template contents or snippets fromdefault_storage.Key Fixes
TemplateUploadMixin.template_name: Checks whether the file exists locally undersettings.MEDIA_ROOT. If not (remote storage), returns the relative storage name directly instead of a nonexistent local path.ReportTemplateBase.get_template_content(): Implemented direct retrieval fromtemplate_file.storage, resolving bucket/location prefix mismatches dynamically.ReportTemplateBase.render_as_string(): Added fallback to render from storage content if template loader resolution fails.InvenTreeStorageTemplateLoader: Added and registered a custom template loader that resolves template snippets and includes directly fromdefault_storage.report/fetcher.pyto gracefully handleweasyprintimport without hardsys.exit(1)when C-libraries are missing during non-PDF test runs.Verification & Testing
Added hermetic test suite
S3ReportTemplateTestwithMockS3Storageinsrc/backend/InvenTree/report/tests.py:test_template_name_remote_storage: Asserts storage-relative path resolution when not on local disk.test_get_template_content_with_prefix: Validates bucket/location prefix resolution.test_get_template_content_without_prefix: Validates direct storage template content loading.test_get_template_content_missing: AssertsTemplateDoesNotExistis raised on missing files.test_render_as_string_fallback: Validates fallback rendering from storage content.test_storage_template_loader_resolution: ValidatesInvenTreeStorageTemplateLoaderresolution.test_render_to_string_with_storage_loader: Validates Djangorender_to_string()resolution from storage.Test Results:
pytest src/backend/InvenTree/report/tests.py -k "S3ReportTemplateTest or DefaultTemplateFileTest"-> 9 passed, 0 faileduv run ruff check-> 0 errorsuv run ruff format --check-> Clean