From patchwork Fri Oct 5 15:31:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Alvares Gomes X-Patchwork-Id: 979536 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42RYnp6wY7z9s3Z for ; Sat, 6 Oct 2018 01:38:54 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 3B8C46750; Fri, 5 Oct 2018 15:38:52 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 20D08B7B for ; Fri, 5 Oct 2018 15:38:50 +0000 (UTC) X-Greylist: delayed 00:07:38 by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id BC68C108 for ; Fri, 5 Oct 2018 15:38:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D81A6CF21; Fri, 5 Oct 2018 15:31:10 +0000 (UTC) Received: from lucas-t460s.redhat.com (ovpn-117-178.ams2.redhat.com [10.36.117.178]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1753762487; Fri, 5 Oct 2018 15:31:09 +0000 (UTC) From: lucasagomes@gmail.com To: dev@openvswitch.org Date: Fri, 5 Oct 2018 16:31:07 +0100 Message-Id: <20181005153107.21667-1-lucasagomes@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 05 Oct 2018 15:31:10 +0000 (UTC) X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] Python: Make Row's __getattr__ less error prone X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Lucas Alvares Gomes Calling getattr() on a Row object after invoking delkey() with a value that does not exist in the object will cause getattr() to fail with a KeyError error. For example: Oct 05 14:59:28 neutron-server[28435]: File "/usr/local/lib/python2.7/dist-packages/ovsdbapp/backend/ovs_idl/connection.py", line 122, in run Oct 05 14:59:28 neutron-server[28435]: txn.results.put(txn.do_commit()) Oct 05 14:59:28 neutron-server[28435]: File "/usr/local/lib/python2.7/dist-packages/ovsdbapp/backend/ovs_idl/transaction.py", line 86, in do_commit Oct 05 14:59:28 neutron-server[28435]: command.run_idl(txn) Oct 05 14:59:28 neutron-server[28435]: File "/usr/local/lib/python2.7/dist-packages/ovsdbapp/backend/ovs_idl/command.py", line 299, in run_idl Oct 05 14:59:28 neutron-server[28435]: if isinstance(getattr(record, self.column), dict): Oct 05 14:59:28 neutron-server[28435]: File "/usr/local/lib/python2.7/dist-packages/ovs/db/idl.py", line 843, in __getattr__ Oct 05 14:59:28 neutron-server[28435]: del dmap[key] Oct 05 14:59:28 neutron-server[28435]: KeyError: 'bogusvalue' This patch is replacing the "del dmap[key]" instruction with a "dmap.pop(key, None)" instruction instead because a pop() (with a default value) will not raise an exception in case the key does not exist in the object in the first place, it will just ignore it. Signed-Off-By: Lucas Alvares Gomes --- python/ovs/db/idl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py index 03110a76f..250e89756 100644 --- a/python/ovs/db/idl.py +++ b/python/ovs/db/idl.py @@ -855,7 +855,7 @@ class Row(object): if removes is not None: for key in removes: if key not in (inserts or {}): - del dmap[key] + dmap.pop(key, None) datum = data.Datum.from_python(column.type, dmap, _row_to_uuid) else: