From 1645d22dc118ee1df0a82a318c50d59861474627 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Tue, 20 Oct 2009 18:17:12 +0200
Subject: [PATCH] =?UTF-8?q?Ensure=20RpcResult=20has=20=E2=80=9Cpayload?=
 =?UTF-8?q?=E2=80=9D=20attribute?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Also add assertions to avoid missing attributes in the future.
They won't be included in optimized bytecode.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/rpc.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lib/rpc.py b/lib/rpc.py
index 61895d563..8701945ab 100644
--- a/lib/rpc.py
+++ b/lib/rpc.py
@@ -97,6 +97,7 @@ class RpcResult(object):
     self.offline = offline
     self.call = call
     self.node = node
+
     if offline:
       self.fail_msg = "Node is marked offline"
       self.data = self.payload = None
@@ -108,16 +109,26 @@ class RpcResult(object):
       if not isinstance(self.data, (tuple, list)):
         self.fail_msg = ("RPC layer error: invalid result type (%s)" %
                          type(self.data))
+        self.payload = None
       elif len(data) != 2:
         self.fail_msg = ("RPC layer error: invalid result length (%d), "
                          "expected 2" % len(self.data))
+        self.payload = None
       elif not self.data[0]:
         self.fail_msg = self._EnsureErr(self.data[1])
+        self.payload = None
       else:
         # finally success
         self.fail_msg = None
         self.payload = data[1]
 
+    assert hasattr(self, "call")
+    assert hasattr(self, "data")
+    assert hasattr(self, "fail_msg")
+    assert hasattr(self, "node")
+    assert hasattr(self, "offline")
+    assert hasattr(self, "payload")
+
   @staticmethod
   def _EnsureErr(val):
     """Helper to ensure we return a 'True' value for error."""
-- 
GitLab