Skip to content

[FIX] purchase_discount: match SQL constraint with Postgres format#3048

Open
randall-vx wants to merge 1 commit intoOCA:16.0from
vauxoo-dev:16.0-fix-sql-const-randallvx
Open

[FIX] purchase_discount: match SQL constraint with Postgres format#3048
randall-vx wants to merge 1 commit intoOCA:16.0from
vauxoo-dev:16.0-fix-sql-const-randallvx

Conversation

@randall-vx
Copy link
Copy Markdown

Odoo drops and recreates constraints if the Python definition does not exactly match the definition returned by PostgreSQL. Because PostgreSQL normalizes the expression to include extra parentheses, the previous definition 'CHECK (discount <= 100.0)' caused a mismatch.

This mismatch led to a DuplicateObject exception during module update because the drop constraint operation was skipped or failed silently and the subsequent add constraint operation failed, raising a WARNING in the logs and failing strict CI checks.

By matching the exact string returned by PostgreSQL, we prevent Odoo from attempting to recreate the constraint on every registry initialization.

Odoo drops and recreates constraints if the Python definition does not
exactly match the definition returned by PostgreSQL. Because PostgreSQL
normalizes the expression to include extra parentheses, the previous
definition 'CHECK (discount <= 100.0)' caused a mismatch.

This mismatch led to a DuplicateObject exception during module update
because the drop constraint operation was skipped or failed silently
and the subsequent add constraint operation failed, raising a WARNING
in the logs and failing strict CI checks.

By matching the exact string returned by PostgreSQL, we prevent Odoo
from attempting to recreate the constraint on every registry initialization.
@OCA-git-bot OCA-git-bot added series:16.0 mod:purchase_discount Module purchase_discount labels May 1, 2026
@randall-vx
Copy link
Copy Markdown
Author

@moylop260 could you review please ?

regards,

@pedrobaeza pedrobaeza added this to the 16.0 milestone May 1, 2026
@moylop260
Copy link
Copy Markdown
Contributor

could you request review of maintainers or authors, please?

@legalsylvain
Copy link
Copy Markdown
Contributor

maybe it should be handled upstream.
I mean, if odoo drop a constraints, then recreate the same constrains, again and again, in each update all, I see it more like a bug (or a non optimization) in Odoo core.
I don't see changing all the constraint of all the OCA modules as as solution.
Don't you think?

@randall-vx
Copy link
Copy Markdown
Author

randall-vx commented May 6, 2026

@legalsylvain thank you for the review!

I agree that Odoo core should handle SQL normalization better. However, as seen in issues like odoo/odoo#40740, this is a long-standing behavior where Odoo relies on a strict string comparison.

By not matching the PostgreSQL output format, we force Odoo to drop and recreate the constraint on every single module update. This is not just a 'non-optimization'; it causes noise in logs and can lead to CI failures or DuplicateObject exceptions during concurrent updates. Given that an upstream fix is unlikely in the short term, following the PostgreSQL normalization format is the standard pragmatic approach in OCA to ensure stable and silent updates.

While I agree this should ideally be handled by the Odoo ORM, providing the normalized string is the current de facto standard in the ecosystem to prevent redundant DDL operations and ensure a clean CI/CD pass, especially considering how sensitive OCA tools are to "WARNINGS" in logs during CI.

odoo/odoo#30334
odoo/odoo#25661
odoo/odoo#28381
odoo/odoo#40740

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

Labels

mod:purchase_discount Module purchase_discount series:16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants