Skip to content

Fix stale attachment IDs causing 404 errors in Emails section#106

Open
MeloveGupta wants to merge 1 commit intopostgres:mainfrom
MeloveGupta:fix/email-attachments-link-mismatch
Open

Fix stale attachment IDs causing 404 errors in Emails section#106
MeloveGupta wants to merge 1 commit intopostgres:mainfrom
MeloveGupta:fix/email-attachments-link-mismatch

Conversation

@MeloveGupta
Copy link

Fix stale attachment IDs causing broken links in Emails section

Root Cause:
parse_and_add_attachments() used get_or_create(), which only applies
defaults during object creation. When the PostgreSQL mail archive
re-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:

  • Existing records are updated when attachment IDs change
  • No duplicate rows are created
  • Attachment links remain valid

Tests:
Add regression tests verifying:

  • Attachment metadata is updated on re-index
  • No duplicate objects are created
  • Existing tests remain green

All tests pass (41/41).
Lint and formatting checks pass.

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.
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.

1 participant