Skip to content

Commit

Permalink
fix(database_cleanup): endless loop
Browse files Browse the repository at this point in the history
I had a case where database_cleanup looped endlessly because of
referential integrity. DROP TABLE was failing because some tables had
foreign keys on tables which were not in the list of tables to delete.
Dropping all contraints linked to the table, even if they are on table which won't be dropped seems to solve the issue.
  • Loading branch information
gurneyalex authored and Camille0907 committed Jul 27, 2023
1 parent 8bfea32 commit c8d1695
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions database_cleanup/models/purge_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,19 @@ def purge(self):
constraint[0],
constraint[3],
)
self.env.cr.execute(
"ALTER TABLE %s DROP CONSTRAINT %s",
(
IdentifierAdapter(constraint[3]),
IdentifierAdapter(constraint[0]),
),
else:
self.logger.info(

Check warning on line 67 in database_cleanup/models/purge_tables.py

View check run for this annotation

Codecov / codecov/patch

database_cleanup/models/purge_tables.py#L67

Added line #L67 was not covered by tests
"Dropping constraint %s on table %s (not to be dropped)",
constraint[0],
constraint[3],
)
self.env.cr.execute(

Check warning on line 72 in database_cleanup/models/purge_tables.py

View check run for this annotation

Codecov / codecov/patch

database_cleanup/models/purge_tables.py#L72

Added line #L72 was not covered by tests
"ALTER TABLE %s DROP CONSTRAINT %s",
(
IdentifierAdapter(constraint[3]),
IdentifierAdapter(constraint[0]),
),
)

self.logger.info("Dropping table %s", line.name)
self.env.cr.execute("DROP TABLE %s", (IdentifierAdapter(line.name),))
Expand Down

0 comments on commit c8d1695

Please sign in to comment.