From d56bc4f21348181fcd8103699192bd31ac4bd805 Mon Sep 17 00:00:00 2001 From: Yang Hongyang Date: Tue, 1 Mar 2016 23:09:17 +0800 Subject: [PATCH] Use obj_attr_is_set to check whether an attr is set in oslo_versionedobject hasattr() have different behaviour between python 2 and 3 [1], while we can not fix oslo_versionedobject [2], we need to use obj_attr_is_set to check whether an attr is set in oslo.versionedobject as their core suggested [2]. [1]. https://docs.python.org/2/library/functions.html#hasattr https://docs.python.org/3/library/functions.html#hasattr [2]. https://review.openstack.org/#/c/285647/ More detailed info, please refer to the launchpad bug page. Change-Id: I9adbbb55e8560a499e8334e954cc904fb8ee3565 Closes-Bug: #1551394 Partially-Implements: blueprint magnum-python3 --- magnum/objects/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/magnum/objects/base.py b/magnum/objects/base.py index 8adca90c9f..995c6d235c 100644 --- a/magnum/objects/base.py +++ b/magnum/objects/base.py @@ -42,7 +42,7 @@ class MagnumObject(ovoo_base.VersionedObject): def as_dict(self): return {k: getattr(self, k) for k in self.fields - if hasattr(self, k)} + if self.obj_attr_is_set(k)} class MagnumObjectDictCompat(ovoo_base.VersionedObjectDictCompat):