From 9e8dd063c6c4215ebda25d0199cec3fb64a81837 Mon Sep 17 00:00:00 2001 From: Roman Podolyaka Date: Tue, 17 Sep 2013 10:21:03 +0300 Subject: [PATCH] Fix AttributeError in Keypair._add_details() _add_details() method copies keypair attributes retrieved from Nova to an instance of Keypair class. Trying to set attribute 'id' fails with AttributeError, because Keypair class has a read-only property 'id'. We can safely omit setting of attribute 'id', because it's just an implementation detail (the id of a table row in a database), and keypairs for a given tenant are uniquely identified using attribute 'name'. Fixes bug 1223934 Change-Id: I1045730e47e9e6ad31fcdfbaefdad77e2f3b2c3e --- novaclient/v1_1/keypairs.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/novaclient/v1_1/keypairs.py b/novaclient/v1_1/keypairs.py index 28bd760c1..cd9e5852f 100644 --- a/novaclient/v1_1/keypairs.py +++ b/novaclient/v1_1/keypairs.py @@ -32,7 +32,15 @@ def _add_details(self, info): dico = 'keypair' in info and \ info['keypair'] or info for (k, v) in dico.items(): - setattr(self, k, v) + # NOTE(rpodolyaka): keypair name allows us to uniquely identify + # a specific keypair, while its id attribute + # is nothing more than an implementation + # detail. We can safely omit the id attribute + # here to ensure setattr() won't raise + # AttributeError trying to set read-only + # property id + if k != 'id': + setattr(self, k, v) @property def id(self):