From 7795ef2742eda964e04423088828b48bf6285d2e Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Thu, 23 Apr 2020 09:25:18 +0200 Subject: [PATCH 1/2] [FIX] unlink cronjobs for the model before purging it --- database_cleanup/models/purge_models.py | 7 +++++++ database_cleanup/tests/test_database_cleanup.py | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/database_cleanup/models/purge_models.py b/database_cleanup/models/purge_models.py index b2c40b93d..c2796c09a 100644 --- a/database_cleanup/models/purge_models.py +++ b/database_cleanup/models/purge_models.py @@ -73,6 +73,13 @@ class CleanupPurgeLineModel(models.TransientModel): self.env['ir.model.constraint'].search([ ('model', '=', line.name), ]).unlink() + cronjobs = self.env['ir.cron'].with_context( + active_test=False + ).search([ + ('model_id.model', '=', line.name), + ]) + if cronjobs: + cronjobs.unlink() relations = self.env['ir.model.fields'].search([ ('relation', '=', row[1]), ]).with_context(**context_flags) diff --git a/database_cleanup/tests/test_database_cleanup.py b/database_cleanup/tests/test_database_cleanup.py index d1d1c795c..e2f1a6deb 100644 --- a/database_cleanup/tests/test_database_cleanup.py +++ b/database_cleanup/tests/test_database_cleanup.py @@ -73,6 +73,11 @@ class TestDatabaseCleanup(TransactionCase): 'name': 'Database cleanup test model', 'model': 'x_database.cleanup.test.model', }) + # and a cronjob for it + cronjob = self.env['ir.cron'].create({ + 'name': 'testcronjob', + 'model_id': self.models.id, + }) self.env.cr.execute( 'insert into ir_attachment (name, res_model, res_id, type) values ' "('test attachment', 'database.cleanup.test.model', 42, 'binary')") @@ -83,6 +88,7 @@ class TestDatabaseCleanup(TransactionCase): self.assertFalse(self.env['ir.model'].search([ ('model', '=', 'x_database.cleanup.test.model'), ])) + self.assertFalse(cronjob.exists()) # create an orphaned table self.env.cr.execute('create table database_cleanup_test (test int)') From b4989587eb8307be40ac9b9ec338568bf1ebda4a Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Thu, 23 Apr 2020 12:25:50 +0200 Subject: [PATCH 2/2] [ADD] pin pygount to a version that doesn't produce warnings --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 22e60039f..b9c961619 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ openpyxl xlrd xlwt pysftp -pygount +# version 1.2.0 deprecates the API module_analysis uses +pygount<1.2.0