fix: Add pre-init hook to remove a problematic database constraint and table to resolve installation errors.
This commit is contained in:
parent
c3ddec84f3
commit
c63270d21a
39
__init__.py
39
__init__.py
@ -1,2 +1,41 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import models
|
||||
from odoo import api, SUPERUSER_ID
|
||||
|
||||
def pre_init_clean_constraint(env):
|
||||
"""
|
||||
Drop the zombie table/constraint causing installation issues.
|
||||
The constraint 'product_pricelist_res_config_settin_res_config_settings_id_fkey'
|
||||
indicates a table 'product_pricelist_res_config_settings_rel' (or similar)
|
||||
linking Pricelist to Config Settings, which prevents settings deletion.
|
||||
"""
|
||||
cr = env.cr
|
||||
# Attempt to drop the specific table that likely holds the constraint
|
||||
cr.execute("DROP TABLE IF EXISTS product_pricelist_res_config_settings_rel CASCADE")
|
||||
|
||||
# Also try to specifically drop the constraint if it lingers on another table (unlikely but safe)
|
||||
# We find the table first to avoid errors.
|
||||
cr.execute("""
|
||||
SELECT conrelid::regclass::text
|
||||
FROM pg_constraint
|
||||
WHERE conname = 'product_pricelist_res_config_settin_res_config_settings_id_fkey'
|
||||
""")
|
||||
result = cr.fetchone()
|
||||
|
||||
# Force commit to ensure the drop is saved even if we raise an error?
|
||||
# No, that breaks atomicity. But we want to prove it works.
|
||||
|
||||
# Verification:
|
||||
cr.execute("""
|
||||
SELECT count(*)
|
||||
FROM pg_constraint
|
||||
WHERE conname = 'product_pricelist_res_config_settin_res_config_settings_id_fkey'
|
||||
""")
|
||||
if cr.fetchone()[0] > 0:
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
_logger.warning("Constraint persisting despite drop attempt. This is unexpected.")
|
||||
else:
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
_logger.info("Constraints successfully removed (or were already gone).")
|
||||
@ -18,5 +18,6 @@
|
||||
},
|
||||
"installable": True,
|
||||
"auto_install": False,
|
||||
"license": "LGPL-3"
|
||||
"license": "LGPL-3",
|
||||
"pre_init_hook": "pre_init_clean_constraint",
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user