From nobody Mon Apr 29 16:55:22 2024 Delivered-To: importer@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; 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 1521684349615955.5698993495573; Wed, 21 Mar 2018 19:05:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 96B7EC04B943; Thu, 22 Mar 2018 02:05:48 +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 87A6C81408; Thu, 22 Mar 2018 02:05:48 +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 79E1E4CA98; Thu, 22 Mar 2018 02:05:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2M25kn4014531 for ; Wed, 21 Mar 2018 22:05:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7FC05111CB8E; Thu, 22 Mar 2018 02:05:46 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D7DD111CB8C for ; Thu, 22 Mar 2018 02:05:42 +0000 (UTC) From: Fam Zheng To: patchew-devel@redhat.com Date: Thu, 22 Mar 2018 10:05:36 +0800 Message-Id: <20180322020536.30263-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH v2] testing: Fix invalidation of prefetch cache upon set_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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 22 Mar 2018 02:05:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Because we have "prefetch_related('properties', 'project')" in MessageManager.series_heads(), "testing.ready" didn't work due to the stale cache of Message._properties, which is built from the stale self.properties, which in turn cannot reflect the .set_property() updates. Fix it with a harder invalidating code path. Signed-off-by: Fam Zheng --- api/models.py | 14 ++++++++++---- tests/test_testing.py | 13 +++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/api/models.py b/api/models.py index de01a61..a672bd4 100644 --- a/api/models.py +++ b/api/models.py @@ -408,9 +408,15 @@ class Message(models.Model): =20 def get_properties(self): if hasattr(self, '_properties'): - return self._properties + if self._properties is not None: + return self._properties + else: + # The prefetch cache is invalidated, query again + all_props =3D MessageProperty.objects.filter(message=3Dsel= f) + else: + all_props =3D self.properties.all() r =3D {} - for m in self.properties.all(): + for m in all_props: if m.blob: r[m.name] =3D load_blob_json(m.value) else: @@ -434,8 +440,8 @@ class Message(models.Model): mp.value =3D value mp.blob =3D blob mp.save() - if hasattr(self, '_properties'): - del(self._properties) + # Invalidate cache + self._properties =3D None =20 def set_property(self, prop, value): old_val =3D self.get_property(prop) diff --git a/tests/test_testing.py b/tests/test_testing.py index 0897bbc..f26da2f 100755 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -43,6 +43,19 @@ class TestingTest(PatchewTestCase): self.msg.set_property("git.tag", "dummy tag") self.msg.set_property("git.base", "dummy base") =20 + def test_testing_ready(self): + self.assertTrue(self.msg.get_property("testing.ready")) + # Set property through series_heads elements must be handled the s= ame + self.msg.set_property("git.repo", None) + self.msg.set_property("git.tag", None) + self.msg.set_property("testing.ready", None) + msg =3D Message.objects.series_heads()[0] + self.assertEqual(self.msg.message_id, msg.message_id) + msg.set_property("git.repo", "dummy repo") + msg.set_property("git.tag", "dummy tag") + msg.set_property("git.base", "dummy base") + self.assertTrue(msg.get_property("testing.ready")) + def msg_testing_done(self, log=3DNone, **report): if not 'passed' in report: report['passed'] =3D True --=20 2.14.3 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel