-
Notifications
You must be signed in to change notification settings - Fork 5
✨(contact) allow to create more than one contact with same email #359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sdemagny
wants to merge
1
commit into
main
Choose a base branch
from
sdem/import_msg_recipients
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
17 changes: 17 additions & 0 deletions
17
src/backend/core/migrations/0010_alter_contact_unique_together.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Generated by Django 5.1.12 on 2025-10-03 11:53 | ||
|
|
||
| from django.db import migrations | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('core', '0009_messagetemplate_blob_maildomain_alter_blob_mailbox_and_more'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterUniqueTogether( | ||
| name='contact', | ||
| unique_together={('email', 'mailbox', 'name')}, | ||
| ), | ||
| ] |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,7 @@ def email_with_duplicate_recipients(): | |
| msg["From"] = "[email protected]" | ||
| msg["To"] = "[email protected], [email protected]" # Duplicate TO | ||
| msg["Cc"] = "[email protected], [email protected]" # Duplicate CC | ||
| msg["Bcc"] = "Jean BCC <[email protected]>, Marie BCC <[email protected]>, [email protected]" # Duplicate BCC | ||
| msg["Subject"] = "Test Subject with Duplicates" | ||
| msg["Message-ID"] = "<[email protected]>" | ||
| msg["Date"] = "Thu, 1 Jan 2024 12:00:00 +0000" | ||
|
|
@@ -442,9 +443,6 @@ def test_imap_import_task_duplicate_recipients( | |
| recipients = message.recipients.all() | ||
| recipient_emails = [r.contact.email for r in recipients] | ||
|
|
||
| # Should have unique recipients (no duplicates) | ||
| assert len(recipient_emails) == len(set(recipient_emails)) | ||
|
|
||
| # Should have the expected recipients | ||
| assert "[email protected]" in recipient_emails | ||
| assert "[email protected]" in recipient_emails | ||
|
|
@@ -456,9 +454,13 @@ def test_imap_import_task_duplicate_recipients( | |
| cc_recipients = message.recipients.filter( | ||
| type=enums.MessageRecipientTypeChoices.CC | ||
| ) | ||
| bcc_recipients = message.recipients.filter( | ||
| type=enums.MessageRecipientTypeChoices.BCC | ||
| ) | ||
|
|
||
| assert to_recipients.count() == 1 # Only one TO recipient (duplicate removed) | ||
| assert cc_recipients.count() == 1 # Only one CC recipient (duplicate removed) | ||
| assert bcc_recipients.count() == 3 # There is differents names for the same email so 3 contacts are created | ||
|
|
||
| # Verify the content | ||
| assert ( | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Risk: nullable field in unique constraint.
Adding
nametounique_togetherwhen the field is nullable (line 1117) can lead to unexpected behavior. In most SQL databases (including PostgreSQL),NULL != NULL, so multiple contacts with the sameemailandmailboxbutNULLnames would be allowed, potentially creating duplicates.Consider one of these solutions:
Solution 1: Make name required
Solution 2: Use application-level default
If name must remain nullable in the database, ensure the application always provides a default value (like the email local-part) before saving, and document this requirement clearly.
Solution 3: Add a database constraint
Add a
CheckConstraintto ensure name is never NULL: