Skip to content
This repository
Browse code

CA-95645: fix Python 2.6 type error comparing DateTime

We compare the result of an rpc call with a constant called
_RECONNECT_AND_RETRY (which was just set to an anonymous function) to decide if
we need to retry the rpc call. When the result is a DateTime object, and we're
using python 2.6+, this comparison (using ==) throws an exception.

The fix is to use the 'is' operator instead of '==', so that we're testing
object equality, and not structural equality. We also set the
_RECONNECT_AND_RETRY constant to object(), which is more sensible than (lambda
_ : ()).

Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com>
  • Loading branch information...
commit 48de47e930ecea87729839751b5fb64496e81956 1 parent 5c1491a
authored December 17, 2012

Showing 1 changed file with 4 additions and 3 deletions. Show diff stats Hide diff stats

  1. 7  scripts/examples/python/XenAPI.py
7  scripts/examples/python/XenAPI.py
@@ -82,7 +82,8 @@ def _details_map(self):
82 82
                      for i in range(len(self.details))])
83 83
 
84 84
 
85  
-_RECONNECT_AND_RETRY = (lambda _ : ())
  85
+# Just a "constant" that we use to decide whether to retry the RPC
  86
+_RECONNECT_AND_RETRY = object()
86 87
 
87 88
 class UDSHTTPConnection(httplib.HTTPConnection):
88 89
     """HTTPConnection subclass to allow HTTP over Unix domain sockets. """
@@ -146,7 +147,7 @@ def xenapi_request(self, methodname, params):
146 147
             while retry_count < 3:
147 148
                 full_params = (self._session,) + params
148 149
                 result = _parse_result(getattr(self, methodname)(*full_params))
149  
-                if result == _RECONNECT_AND_RETRY:
  150
+                if result is _RECONNECT_AND_RETRY:
150 151
                     retry_count += 1
151 152
                     if self.last_login_method:
152 153
                         self._login(self.last_login_method,
@@ -161,7 +162,7 @@ def xenapi_request(self, methodname, params):
161 162
 
162 163
     def _login(self, method, params):
163 164
         result = _parse_result(getattr(self, 'session.%s' % method)(*params))
164  
-        if result == _RECONNECT_AND_RETRY:
  165
+        if result is _RECONNECT_AND_RETRY:
165 166
             raise xmlrpclib.Fault(
166 167
                 500, 'Received SESSION_INVALID when logging in')
167 168
         self._session = result

0 notes on commit 48de47e

Please sign in to comment.
Something went wrong with that request. Please try again.