diff --git a/runbot/migrations/17.0.5.8/post-migration.py b/runbot/migrations/17.0.5.8/post-migration.py index 3dc783af..dea6d62a 100644 --- a/runbot/migrations/17.0.5.8/post-migration.py +++ b/runbot/migrations/17.0.5.8/post-migration.py @@ -5,6 +5,11 @@ _logger = logging.getLogger(__name__) def migrate(cr, version): + #cr.execute('CREATE SEQUENCE runbot_build_error_id_seq') + # update sequence + cr.execute("SELECT setval('runbot_build_error_id_seq', (SELECT MAX(id) FROM runbot_build_error))") + cr.execute("ALTER TABLE runbot_build_error ALTER COLUMN id SET DEFAULT nextval('runbot_build_error_id_seq')") + # get seen infos cr.execute("SELECT error_content_id, min(build_id), min(log_date), max(build_id), max(log_date), count(DISTINCT build_id) FROM runbot_build_error_link GROUP BY error_content_id") vals_by_error = {error: vals for error, *vals in cr.fetchall()} diff --git a/runbot/migrations/17.0.5.8/pre-migration.py b/runbot/migrations/17.0.5.8/pre-migration.py index fb550ef4..1b6bf034 100644 --- a/runbot/migrations/17.0.5.8/pre-migration.py +++ b/runbot/migrations/17.0.5.8/pre-migration.py @@ -1,4 +1,7 @@ def migrate(cr, version): cr.execute('ALTER TABLE runbot_build_error RENAME TO runbot_build_error_content') + cr.execute('CREATE SEQUENCE runbot_build_error_content_id_seq') + cr.execute("SELECT setval('runbot_build_error_content_id_seq', (SELECT MAX(id) FROM runbot_build_error_content))") + cr.execute("ALTER TABLE runbot_build_error_content ALTER COLUMN id SET DEFAULT nextval('runbot_build_error_content_id_seq')") cr.execute('ALTER TABLE runbot_build_error_content ADD COLUMN first_seen_build_id INT') cr.execute('ALTER TABLE runbot_build_error_link RENAME COLUMN build_error_id TO error_content_id') diff --git a/runbot/models/build_error.py b/runbot/models/build_error.py index c8c68146..02d0de49 100644 --- a/runbot/models/build_error.py +++ b/runbot/models/build_error.py @@ -70,9 +70,11 @@ def _compute_related_error_content_ids(field_name): class BuildError(models.Model): _name = "runbot.build.error" - _description = "An object to manage a group of errors log that fit together and assign them to a team" + _description = "Build error" + # An object to manage a group of errors log that fit together and assign them to a team _inherit = ('mail.thread', 'mail.activity.mixin', 'runbot.build.error.seen.mixin') + name = fields.Char("Name") active = fields.Boolean('Open (not fixed)', default=True, tracking=True) description = fields.Text("Description", store=True, compute='_compute_description') @@ -320,7 +322,7 @@ class BuildError(models.Model): class BuildErrorContent(models.Model): _name = 'runbot.build.error.content' - _description = "Build error log" + _description = "Build error content" _inherit = ('mail.thread', 'mail.activity.mixin', 'runbot.build.error.seen.mixin') _rec_name = "id" @@ -360,9 +362,10 @@ class BuildErrorContent(models.Model): previous_error_content = error_content.search([ ('fingerprint', '=', error_content.fingerprint), ('error_id.active', '=', False), + ('error_id.id', '!=', error_content.error_id.id or False), ('id', '!=', error_content.id or False), - ]) - if previous_error_content and previous_error_content != error_content.error_id: + ], order="id desc", limit=1) + if previous_error_content: error_content.error_id.message_post(body=f"An historical error was found for error {error_content.id}: {previous_error_content.id}") error_content.error_id.previous_error_id = previous_error_content.error_id