Skip to content
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

[FIX] error in compute_notify_recipients query #1184

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from

Conversation

gfcapalbo
Copy link

@gfcapalbo gfcapalbo commented Sep 1, 2023

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:

exept_partner
[817, 245]

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

Copy link

@NL66278 NL66278 left a comment

Choose a reason for hiding this comment

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

👍 LGTM. Checked workings in psql. Please also submit to core Odoo repo.

@cvinh
Copy link

cvinh commented Sep 1, 2023

I think Odoo will not take it as v14 is going to expire soon
Does this also appear in v15 & v16 ?

@gfcapalbo
Copy link
Author

gfcapalbo commented Sep 4, 2023

Member

I think Odoo will not take it as v14 is going to expire soon Does this also appear in v15 & v16 ?

The code does not exist in V15 anymore. in the same place https://github.com/OCA/OCB/blob/15.0/addons/mail/models/mail_thread.py#L2464-L2494
it has been refactored.

the function then uses a query in mail.follower:
https://github.com/OCA/OCB/blob/16.0/addons/mail/models/mail_followers.py#L77

But here i only see the use of = with ANY ( wich is correct) , never the incorrect use of != with ANY (the logical fallacy exposed by this MR).

so it seems >14 is unaffected.

@OCA-git-bot
Copy link

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants