Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions website_membership_registration/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _compute_membership_group_ids(self):
)
return res

@api.constrains("email", "membership_state")
@api.constrains("email", "membership_state", "active")
def _check_mail_unique(self):
for partner in self:
if not partner.email or partner.membership_state == "none":
Expand All @@ -78,9 +78,10 @@ def _check_mail_unique(self):
self.env.cr.execute(
"""
SELECT id FROM res_partner
WHERE email ILIKE %s
WHERE LOWER(email) = LOWER(%s)
AND id != %s
AND membership_state != 'none'
AND active = TRUE
Comment on lines +81 to +84
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SQL now filters duplicates to active = TRUE, but the constraint is only declared on email and membership_state. If a user archives/unarchives a partner (toggles active), this constraint won't run, which can allow creating two active members with the same email after reactivation. Include active in the @api.constrains(...) fields (or enforce uniqueness regardless of active) so activation changes also trigger the check.

Copilot uses AI. Check for mistakes.
LIMIT 1
""",
(partner.email, partner.id),
Expand Down
Loading