[FIX] purchase_discount: match SQL constraint with Postgres format#3048
[FIX] purchase_discount: match SQL constraint with Postgres format#3048randall-vx wants to merge 1 commit intoOCA:16.0from
Conversation
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.
|
@moylop260 could you review please ? regards, |
|
could you request review of maintainers or authors, please? |
|
maybe it should be handled upstream. |
|
@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 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.