[FIX] error in compute_notify_recipients query #1184
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.
Description of the issue/feature this PR addresses:
We found ourselves in very specific conditions raising a sql constraint forbidding duplicate mail.notifications on same partner when simply posting a message in a channel, and were also followers of the channel record itself.
There seems to be an error in the query in:
https://github.com/OCA/OCB/blob/14.0/addons/mail/models/mail_thread.py#L2520C2-L2529
in our specific case exept_partner was already computed as:
but the query would still return 817 in our results, therefore adding a duplicate partner to the response.
By analyzing the query, and the logic of the code in https://github.com/OCA/OCB/blob/14.0/addons/mail/models/mail_thread.py#L2469 i see that the use of "ANY" is incorrect.
By writing :
and p.id != ANY('{817,245}') ;
if p.id is 817 we are actually expressing : and ( 817 != 817 OR 817 != 245) therefore including 817 in our results.
Actually we are including everything, as-is this condition restricts no values, it has no effect.
By changing this to
and p.id != ALL('{817,245}') ;
if p.id is 817 we are actually expressing : and ( 817 != 817 AND 817 != 245) wich is what we want , and wich was the intention of the query itself, Not to return partners we had already added in the code before.
This Query needs to be changed, We have deployed this on production and are happy with it.
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr