fix broken images in subscription emails - #3737
Open
shanbady wants to merge 7 commits into
Open
Conversation
for more information, see https://pre-commit.ci
Comment on lines
+248
to
+250
| response = requests.head( | ||
| url, timeout=settings.REQUESTS_TIMEOUT, allow_redirects=True | ||
| ) |
Comment on lines
+256
to
+258
| response = requests.get( | ||
| url, timeout=settings.REQUESTS_TIMEOUT, stream=True | ||
| ) |
…uest forgery' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
OpenAPI ChangesNo changes detected Unexpected changes? Ensure your branch is up-to-date with |
…side request forgery'" This reverts commit ac761b9.
shanbady
marked this pull request as ready for review
August 9, 2026 19:54
Contributor
There was a problem hiding this comment.
Pull request overview
Adds backend validation and fallback handling for broken images in subscription emails.
Changes:
- Adds cached image URL reachability checks.
- Uses default images for unreachable email thumbnails.
- Schedules pruning and reindexing for unreachable resource images.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
main/settings_celery.py |
Schedules weekly image pruning. |
learning_resources/utils.py |
Adds cached URL reachability checks. |
learning_resources/utils_test.py |
Tests reachability and caching. |
learning_resources/tasks.py |
Prunes unreachable images and reindexes resources. |
learning_resources/tasks_test.py |
Tests image pruning behavior. |
learning_resources_search/tasks.py |
Applies fallback images to subscription emails. |
learning_resources_search/tasks_test.py |
Tests email image fallback behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| url, timeout=settings.REQUESTS_TIMEOUT, stream=True | ||
| ) | ||
| response.close() | ||
| reachable = response.ok |
| ) | ||
| removed = 0 | ||
| for image in LearningResourceImage.objects.filter(id__in=image_ids).iterator(): | ||
| if image_url_is_reachable(image.url): |
Comment on lines
+864
to
+868
| image_ids = ( | ||
| LearningResource.objects.filter(published=True, image__isnull=False) | ||
| .values_list("image_id", flat=True) | ||
| .distinct() | ||
| ) |
Comment on lines
+870
to
+871
| for image in LearningResourceImage.objects.filter(id__in=image_ids).iterator(): | ||
| if image_url_is_reachable(image.url): |
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.
What are the relevant tickets?
Closes https://github.com/mitodl/hq/issues/12708
Description (What does it do?)
This PR ensures that images in emails properly fallback instead of appearing broken. There does not appear to be a single solution that works client-side and is supported by all mail clients. The proper fix in this case is to do a HEAD request - set the default (on the backend) if it broken.
How can this be tested?
Additional Context
There is a codeql failure in this PR that is being addressed separately as part of https://github.com/mitodl/hq/issues/12773