Skip to content

[19.0][IMP] database_cleanup: Drop dependent views before dropping tables#3676

Open
quoc-pn wants to merge 1 commit into
OCA:19.0from
komit-consulting:19.0-database_cleanup-purge-table-drop-dependent-view
Open

[19.0][IMP] database_cleanup: Drop dependent views before dropping tables#3676
quoc-pn wants to merge 1 commit into
OCA:19.0from
komit-consulting:19.0-database_cleanup-purge-table-drop-dependent-view

Conversation

@quoc-pn

@quoc-pn quoc-pn commented Jul 15, 2026

Copy link
Copy Markdown
Member

Problems

The current implementation only removes constraints before dropping tables. However, PostgreSQL also prevents dropping a table when other database objects, such as views or materialized views, depend on it.

psycopg2.errors.DependentObjectsStillExist: cannot drop table hr_employee because other objects depend on it
DETAIL:  view hr_employee_public depends on table hr_employee
view hr_holidays_remaining_leaves_user depends on table hr_employee
view hr_leave_report_calendar depends on table hr_employee
HINT:  Use DROP ... CASCADE to drop the dependent objects too.

Solution

Before dropping a table, detect and remove all views or materialized views that reference the table. Once the dependent objects have been removed, the table can be dropped safely without raising DependentObjectsStillExist.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants