From nobody Sat Apr 20 03:08:24 2024 Delivered-To: importer2@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1543416359475648.8294418505451; Wed, 28 Nov 2018 06:45:59 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51018308429B; Wed, 28 Nov 2018 14:45:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3D5DB19754; Wed, 28 Nov 2018 14:45:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2DA333F600; Wed, 28 Nov 2018 14:45:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wASEjEIV000536 for ; Wed, 28 Nov 2018 09:45:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id AD9E34140; Wed, 28 Nov 2018 14:45:14 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B3286A6BA for ; Wed, 28 Nov 2018 14:45:08 +0000 (UTC) Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9134C83F3E for ; Wed, 28 Nov 2018 14:45:06 +0000 (UTC) Received: by mail-wr1-f46.google.com with SMTP id j2so26602794wrw.1 for ; Wed, 28 Nov 2018 06:45:06 -0800 (PST) Received: from localhost.localdomain ([2001:b07:6468:f312:60a1:384e:4c17:72ad]) by smtp.gmail.com with ESMTPSA id z12sm7392508wrh.35.2018.11.28.06.45.03 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Nov 2018 06:45:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=IY/Xq7xIVCTuBL+6K9FVU1Sq0/HKd81BZgSQN/xTQR8=; b=f63wHY3SFjmWyVwGi59pgA4T2vxdWnNbslHp+a0dhRJgLGzQb78RRNHafmYwxrizTB JUkT9++oPvOM8CxcKRVxiSAfQL9/cDGiHQo14NT1MmYr4ZgFWtViz2q2LmIY27MIuvvp P6BDlcUEbP30p0+3iVyjU9hF36GM87kffLE1uHhuLtfqoPFK6DD/DPkgQypR4oABYIYj f/UdDGc6aRHJ3174YENuHYVRYddcBS4KcGyqaR0+Z8N6uh6lsnf97M3bLA1zMd8CtvIQ cKhPrAhKMKPPMK5HuaP4rhOv5Hi28VfV9UV3gMUkEQr14+mFlmlM7axuU2aZNYXtLqIM VHWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :mime-version:content-transfer-encoding; bh=IY/Xq7xIVCTuBL+6K9FVU1Sq0/HKd81BZgSQN/xTQR8=; b=H6FZc+uJoh2xL5wJXLyPjMvWdl8yZb6mJhrXnS7xEr7YUfXMjqF6h/5viMRjUQP4Dg jRjivt1Z7J/0gdh+3hb9rOglWyXaLytUfRJCvX3NRSerKqhk0OfJesQOv7uII92qjEVy SWI2R5lqK7pGNSRTeGvIkUqpsdf63zR3SOuTAxRJ+/TsO/Bd77G86+M1xD5XqCq2arih skvW82EiKbFGzb8Abm1/lGbNOqx851rS0qjwocA4qBOCSGtC9TNGJ6Y5pCfY20fjKB0a zqIaT5C5rKxi9kwcvEjKkiMYBfmSevwJnq2S8gA+5rsMdoy1WoBYXO9F85v8jJOVKKD+ awdw== X-Gm-Message-State: AA+aEWYnRMGSlW92ohKVTmLi82EQrPw7162qvKVEG5oyOiSDjcXLPfz+ rH/GzqpcRfyFXpkkD8+w1hZrzCh7 X-Google-Smtp-Source: AFSGD/XIL9Ask6cg5L/JqDRqAdMerMSfb5UCbg2l9pqWNXh67Ke9GbCD/5VMZJsjfQLhwBhNv8vtKw== X-Received: by 2002:a5d:4a8e:: with SMTP id o14mr30208453wrq.159.1543416304695; Wed, 28 Nov 2018 06:45:04 -0800 (PST) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 28 Nov 2018 15:44:59 +0100 Message-Id: <20181128144459.11009-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 28 Nov 2018 14:45:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 28 Nov 2018 14:45:06 +0000 (UTC) for IP:'209.85.221.46' DOMAIN:'mail-wr1-f46.google.com' HELO:'mail-wr1-f46.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.24 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.221.46 mail-wr1-f46.google.com 209.85.221.46 mail-wr1-f46.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH] models: avoid IntegrityError when clearing log property X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 28 Nov 2018 14:45:58 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Result's log property provides some magic to hide the existence of the LogEntry table (which in turn is only there to optimize access to results, since the logs are rarely needed). However, deleting the entry directly in the setter does not work, because at this point the entry is still referenced in the Result table. Postgres complains about a foreign key constraint violation when the setter calls entry.delete(). To fix this, which shows up as an error in the git-reset action, detect at save time whether the log_entry became None, and if so delete it _after_ saving the model. While I am touching the code, fix the override of save() to correctly pass the arguments to the superclass. --- api/models.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/api/models.py b/api/models.py index e24098b..8ec89b6 100644 --- a/api/models.py +++ b/api/models.py @@ -74,11 +74,19 @@ class Result(models.Model): def is_running(self): return self.status =3D=3D self.RUNNING =20 - def save(self): + def save(self, *args, **kwargs): self.last_update =3D datetime.datetime.utcnow() old_result =3D Result.objects.filter(pk=3Dself.pk).first() old_status =3D old_result.status if old_result else None - super(Result, self).save() + old_entry =3D old_result.log_entry if old_result else None + super(Result, self).save(*args, **kwargs) + + if self.log_entry is None and old_entry is not None: + # Quick way to check if the field was actually saved to the da= tabase + new_result =3D Result.objects.filter(pk=3Dself.pk).first() + if new_result.log_entry is None: + old_entry.delete() + emit_event("ResultUpdate", obj=3Dself.obj, old_status=3Dold_status, result=3Dself) =20 @@ -109,18 +117,15 @@ class Result(models.Model): =20 @log.setter def log(self, value): - entry =3D self.log_entry if value is None: - if entry is not None: - self.log_entry =3D None - entry.delete() - else: - if entry is None: - entry =3D LogEntry() - entry.data =3D value - entry.save() - if self.log_entry is None: - self.log_entry =3D entry + self.log_entry =3D None + return + + entry =3D self.log_entry or LogEntry() + entry.data =3D value + entry.save() + if self.log_entry is None: + self.log_entry =3D entry =20 def get_log_url(self, request=3DNone): if not self.is_completed() or self.renderer is None: --=20 2.19.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel