[FIX] website_membership_registration: Update _check_mail_unique to use sql query instead of search to avoid maximum recursion depth issue#139
Conversation
…se sql query instead of search to avoid maximum recursion depth issue
There was a problem hiding this comment.
Pull request overview
Updates the website_membership_registration email uniqueness constraint to avoid recursion by replacing an ORM search() with a direct SQL query when checking for existing member partners.
Changes:
- Reworked
_check_mail_uniqueto usecr.execute()againstres_partnerfor the “existing member” email check. - Kept the “existing user login” uniqueness check via ORM search.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| self.env.cr.execute( | ||
| """ | ||
| SELECT id FROM res_partner | ||
| WHERE email ILIKE %s |
There was a problem hiding this comment.
The SQL condition email ILIKE %s treats % and _ in the provided email as wildcards (e.g., underscores are common in emails). That can cause false positives compared to Odoo's =ilike domain operator (which escapes wildcards for exact matching). Consider switching to an equality-based comparison such as LOWER(email) = LOWER(%s) (or explicitly escaping LIKE wildcards and adding an ESCAPE clause) to preserve exact-match semantics.
| WHERE email ILIKE %s | |
| WHERE LOWER(email) = LOWER(%s) |
| SELECT id FROM res_partner | ||
| WHERE email ILIKE %s | ||
| AND id != %s | ||
| AND membership_state != 'none' |
There was a problem hiding this comment.
This direct SQL query bypasses Odoo's usual active_test filtering. Previously, self.search(...) would (by default) ignore archived partners, but the SQL will match inactive records too, potentially blocking reuse of an email that only exists on an archived member. If the old behavior is desired, add an AND active (or equivalent) predicate to the SQL to align with the ORM search semantics.
| AND membership_state != 'none' | |
| AND membership_state != 'none' | |
| AND active |
No description provided.