Skip to content

Commit

Permalink
Merge pull request #3999 from chloerh/del-attr
Browse files Browse the repository at this point in the history
setup_attrs:Delete attribute if the value is explicitly set to None
  • Loading branch information
Yingshun committed Sep 23, 2024
2 parents 5d272aa + 447b028 commit 8fb6889
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions virttest/libvirt_xml/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@ def setup_attrs(self, **attrs):
'Cannot set attribute "%s" to %s object.'
"There is no such attribute." % (key, self.__class__)
)

# Delete attribute if the value is explicitly set to None
if value is None:
del_func = eval("self.del_%s" % key)
if not isinstance(del_func, propcan.PropCanBase):
logging.warning(f"Customized del func {del_func} might not work")
del_func()
continue

get_func = eval("self.get_%s" % key)

# Skip Getters if they are customized
Expand Down

0 comments on commit 8fb6889

Please sign in to comment.