Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion database_cleanup/models/purge_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,16 @@ class CleanupPurgeWizardTable(models.TransientModel):
_name = "cleanup.purge.wizard.table"
_description = "Purge tables"

blacklist = [
"endpoint_route", # web-api/endpoint_route_handler
]

@api.model
def find(self):
"""
Search for tables and views that cannot be instantiated.
"""
known_tables = []
known_tables = list(self.blacklist)
for model in self.env["ir.model"].search([]):
if model.model not in self.env:
continue
Expand Down
16 changes: 10 additions & 6 deletions database_cleanup/tests/test_purge_tables.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Copyright 2021 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from psycopg2 import ProgrammingError

from odoo.tests.common import tagged
from odoo.tools import mute_logger
from odoo.tools import sql

from .common import Common, environment

Expand All @@ -17,7 +16,12 @@ def test_empty_table(self):
env.cr.execute("create table database_cleanup_test (test int)")
wizard = env["cleanup.purge.wizard.table"].create({})
wizard.purge_all()
with self.assertRaises(ProgrammingError):
with env.registry.cursor() as cr:
with mute_logger("odoo.sql_db"):
cr.execute("select * from database_cleanup_test")
self.assertFalse(sql.table_exists(env.cr, "database_cleanup_test"))

def test_blacklist(self):
"""A table mentioned in the blacklist is not purged"""
with environment() as env:
env.cr.execute("create table if not exists endpoint_route (test int)")
wizard = env["cleanup.purge.wizard.table"].create({})
wizard.purge_all()
self.assertTrue(sql.table_exists(env.cr, "endpoint_route"))
Loading