From fef9ae98010d2cec06eef9fc70b840c6bea72e0b Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Mon, 4 Sep 2023 15:50:56 +0200 Subject: [PATCH] [FIX] runbot: ensure that commit date is always set When exporting a commit, the commit date is used in the `tar` command to set the date of the exported folder. On the other hand it happens that a commit is not found in the database and should be quickly created on the fly. e.g.: with the `_get` method. In this case, if the commit needs to be exported later, the method fails and may break a runbot build. It happened with a custom python step. --- runbot/models/commit.py | 7 +++++++ runbot/tests/test_commit.py | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/runbot/models/commit.py b/runbot/models/commit.py index f04228ed..b9cdfaa0 100644 --- a/runbot/models/commit.py +++ b/runbot/models/commit.py @@ -34,6 +34,13 @@ class Commit(models.Model): dname = fields.Char('Display name', compute='_compute_dname') rebase_on_id = fields.Many2one('runbot.commit', 'Rebase on commit') + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if 'date' not in vals: + vals['date'] = fields.Datetime.now() + return super().create(vals_list) + def _get(self, name, repo_id, vals=None, rebase_on_id=False): commit = self.search([('name', '=', name), ('repo_id', '=', repo_id), ('rebase_on_id', '=', rebase_on_id)]) if not commit: diff --git a/runbot/tests/test_commit.py b/runbot/tests/test_commit.py index 96b3f505..6185c759 100644 --- a/runbot/tests/test_commit.py +++ b/runbot/tests/test_commit.py @@ -6,6 +6,17 @@ from werkzeug.urls import url_parse from odoo.tests.common import HttpCase, new_test_user, tagged from odoo.tools import mute_logger +from .common import RunbotCaseMinimalSetup + +class TestCommitDate(RunbotCaseMinimalSetup): + + def test_commit_has_date(self): + commit = self.Commit.create({ + 'name': 'caca00caca00ffffffffffffffffffffffffffff', + 'repo_id': self.repo_server.id + }) + + self.assertNotEqual(commit.date, False, "A commit should always have a date") @tagged('post_install', '-at_install') class TestCommitStatus(HttpCase):