Fix stale attachment IDs causing 404 errors in Emails section#106
Open
MeloveGupta wants to merge 1 commit intopostgres:mainfrom
Open
Fix stale attachment IDs causing 404 errors in Emails section#106MeloveGupta wants to merge 1 commit intopostgres:mainfrom
MeloveGupta wants to merge 1 commit intopostgres:mainfrom
Conversation
Change get_or_create to update_or_create in parse_and_add_attachments() so that attachmentid and filename are refreshed when the mail archive re-indexes attachments. Previously, defaults were only applied on record creation, leaving stale IDs that pointed to non-existent attachments. Add regression tests verifying attachment metadata is updated correctly.
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.
Fix stale attachment IDs causing broken links in Emails section
Root Cause:
parse_and_add_attachments() used get_or_create(), which only applies
defaultsduring object creation. When the PostgreSQL mail archivere-indexes attachments and assigns new attachment IDs, existing
MailThreadAttachment records retained stale attachmentid values.
This resulted in attachment URLs pointing to non-existent resources (404).
Fix:
Replace get_or_create() with update_or_create() so that attachmentid
and filename are refreshed whenever attachment metadata changes.
This ensures:
Tests:
Add regression tests verifying:
All tests pass (41/41).
Lint and formatting checks pass.