From c531b0eac28cd6769ff60d2c3fb3da21ddec1cca Mon Sep 17 00:00:00 2001 From: Wojtek Porczyk Date: Wed, 24 Feb 2016 12:22:20 +0100 Subject: [PATCH] qubes: fix None serialisation for VMProperty Note that None != default (no attribute in XML at all). This is reworked 27eddcb WIP core: fix deserializing None for VMProperty by Marek. --- qubes/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qubes/__init__.py b/qubes/__init__.py index 560388c5..2a2fae84 100644 --- a/qubes/__init__.py +++ b/qubes/__init__.py @@ -1028,6 +1028,8 @@ class VMProperty(property): and ``setter`` ''' + _none_value = '' + def __init__(self, name, vmclass=qubes.vm.BaseVM, allow_none=False, **kwargs): if 'type' in kwargs: @@ -1043,13 +1045,16 @@ class VMProperty(property): "'vmclass' should specify a subclass of qubes.vm.BaseVM") super(VMProperty, self).__init__(name, - saver=(lambda self, prop, value: value.name if value else 'None'), + saver=(lambda self_, prop, value: + self._none_value if value is None else value.name), **kwargs) self.vmclass = vmclass self.allow_none = allow_none def __set__(self, instance, value): + if value == self._none_value: + value = None if value is None: if self.allow_none: super(VMProperty, self).__set__(instance, value)