Feat/include template files in sends#2936
Merged
Merged
Conversation
…e file attachments during send
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds support for including template-level file attachments in email sends (API/admin; one-off and bulk), with Redis-based caching of template file metadata for bulk jobs to stabilize attachment sets and reduce repeated DB lookups.
Changes:
- Added Redis-backed retrieval for template file metadata and a download helper to turn those into provider attachments (
app/delivery/send_to_providers.py). - Added a Celery-side pre-cache step for bulk email jobs to store template file metadata in Redis (
app/celery/tasks.py). - Added a DAO method to fetch “ready” template files and new tests covering the new attachment flow (
app/dao/files_dao.py,tests/app/delivery/test_template_attachments.py).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| tests/app/delivery/test_template_attachments.py | Adds unit/integration-style tests for caching, downloading, and merging template attachments into sends. |
| app/delivery/send_to_providers.py | Implements cache/DB retrieval + download of template files, and merges them into send_email_to_provider attachments while excluding template_attach entries from personalisation file processing. |
| app/dao/files_dao.py | Adds a DAO for retrieving “ready” template files used by both the Celery pre-cache and delivery layer. |
| app/celery/tasks.py | Adds a pre-cache step for bulk email jobs to store template file metadata in Redis. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Jul 8, 2026
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 | Résumé
This pull request introduces a new mechanism to efficiently handle template file attachments for api and admin sending (both one-off and bulk).
It employs caching in redis to ensure the same set of attachments will be sent for a bulk job, even if users change the template during the send. This also reduces database load and file download duplication for bulk jobs.
The most important changes are:
Caching and Retrieval of Template File Attachments:
_cache_template_files_for_jobinapp/celery/tasks.pyto pre-cache template file metadata in Redis for bulk email jobs, reducing redundant database queries and downloads during job processing. This function is called at the start of email job processing. [1] [2]_get_template_files_from_cache_or_dband_get_template_attachmentsinapp/delivery/send_to_providers.pyto fetch template file metadata from Redis (for bulk jobs) or the database (for one-off sends or cache misses), and to download the files from the document download service.Integration with Email Sending Workflow:
send_email_to_providerinapp/delivery/send_to_providers.pyto merge template file attachments (fetched and downloaded using the new caching mechanism) with any personalized file attachments before sending emails.Database Access Enhancements:
dao_get_ready_files_by_template_idinapp/dao/files_dao.pyto retrieve only files that are scanned and ready for sending, and updated imports accordingly. [1] [2]app/celery/tasks.pyandapp/delivery/send_to_providers.pyto include the new DAO function andredis_store. [1] [2] [3] [4]Personalization Logic Update:
send_email_to_providerto exclude template attachments from the list of personalized file attachments, ensuring that template and personalized files are handled separately and correctly.Related Issues | Cartes liées
Test instructions | Instructions pour tester la modification
ADMIN
API
Bulk
Release Instructions | Instructions pour le déploiement
None.
Reviewer checklist | Liste de vérification du réviseur