[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.
This commit is contained in:
Christophe Monniez 2023-09-04 15:50:56 +02:00 committed by xdo
parent ce47661bbc
commit fef9ae9801
2 changed files with 18 additions and 0 deletions

View File

@ -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:

View File

@ -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):