From e51e6451c1fd7bdde5aa98237a7b03bc6aa399b0 Mon Sep 17 00:00:00 2001 From: Spitap Date: Sun, 30 Apr 2023 13:48:26 +0200 Subject: [PATCH] Fixed m2m relationship on fresh domain instance Co-Authored-By: Antoine Nguyen --- .github/workflows/modoboa.yml | 2 +- modoboa/admin/models/domain.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/modoboa.yml b/.github/workflows/modoboa.yml index cacf20a0e..39d8be9ba 100644 --- a/.github/workflows/modoboa.yml +++ b/.github/workflows/modoboa.yml @@ -97,7 +97,7 @@ jobs: pip install -r mysql-requirements.txt echo "DB=mysql" >> $GITHUB_ENV - name: Test with pytest - if: ${{ matrix.python-version != '3.8' || matrix.database != 'postgres' }} + if: ${{ matrix.database != 'postgres' }} run: | python ./tests.py cd test_project diff --git a/modoboa/admin/models/domain.py b/modoboa/admin/models/domain.py index dd997b9a6..3cc25bf90 100644 --- a/modoboa/admin/models/domain.py +++ b/modoboa/admin/models/domain.py @@ -313,7 +313,8 @@ class Domain(mixins.MessageLimitMixin, AdminObject): def save(self, *args, **kwargs): """Store current data if domain is renamed.""" - if self.oldname != self.name: + # We check that the instance exists to use m2m relationship + if self.pk and self.oldname != self.name: self.old_mail_homes = { mb.id: mb.mail_home for mb in self.mailbox_set.all() }