[ovs-git] [openvswitch/ovs] f192ba: Python: Make Row's __getattr__ less error prone

GitHub noreply at github.com
Fri Oct 5 16:26:35 UTC 2018


  Branch: refs/heads/master
  Home:   https://github.com/openvswitch/ovs
  Commit: f192ba279e9c7d378f348017281b14f1585e0eaa
      https://github.com/openvswitch/ovs/commit/f192ba279e9c7d378f348017281b14f1585e0eaa
  Author: Lucas Alvares Gomes <lucasagomes at gmail.com>
  Date:   2018-10-05 (Fri, 05 Oct 2018)

  Changed paths:
    M python/ovs/db/idl.py

  Log Message:
  -----------
  Python: Make Row's __getattr__ less error prone

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 <lucasagomes at gmail.com>
Signed-off-by: Ben Pfaff <blp at ovn.org>



      **NOTE:** This service has been marked for deprecation: https://developer.github.com/changes/2018-04-25-github-services-deprecation/

      Functionality will be removed from GitHub.com on January 31st, 2019.


More information about the git mailing list