-
Notifications
You must be signed in to change notification settings - Fork 9
[FIX] website_membership_registration: Update _check_mail_unique to use sql query instead of search to avoid maximum recursion depth issue #139
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -71,34 +71,40 @@ def _compute_membership_group_ids(self): | |||||||
| @api.constrains("email", "membership_state") | ||||||||
| def _check_mail_unique(self): | ||||||||
| for partner in self: | ||||||||
| if partner.email and partner.membership_state != "none": | ||||||||
| member_found = self.search( | ||||||||
| [ | ||||||||
| ("email", "=ilike", partner.email), | ||||||||
| ("id", "!=", partner.id), | ||||||||
| ("membership_state", "!=", "none"), | ||||||||
| ], | ||||||||
| limit=1, | ||||||||
| ) | ||||||||
| if member_found: | ||||||||
| raise ValidationError( | ||||||||
| self.env._( | ||||||||
| "Another Member already exists with email %s", partner.email | ||||||||
| ) | ||||||||
| if not partner.email or partner.membership_state == "none": | ||||||||
| continue | ||||||||
|
|
||||||||
| # Use a direct SQL query to avoid triggering recursive Odoo search/constrain loops | ||||||||
| self.env.cr.execute( | ||||||||
| """ | ||||||||
| SELECT id FROM res_partner | ||||||||
| WHERE email ILIKE %s | ||||||||
| AND id != %s | ||||||||
| AND membership_state != 'none' | ||||||||
|
||||||||
| AND membership_state != 'none' | |
| AND membership_state != 'none' | |
| AND active |
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.
The SQL condition
email ILIKE %streats%and_in the provided email as wildcards (e.g., underscores are common in emails). That can cause false positives compared to Odoo's=ilikedomain operator (which escapes wildcards for exact matching). Consider switching to an equality-based comparison such asLOWER(email) = LOWER(%s)(or explicitly escaping LIKE wildcards and adding anESCAPEclause) to preserve exact-match semantics.