Skip to content

Commit 7676342

Browse files
committed
fix #235: sometimes IronPython screws up something and returns an old-style class for service response
1 parent 2b1c9a8 commit 7676342

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/compas_fab/backends/ros/service_description.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from __future__ import division
99
from __future__ import print_function
1010

11+
import types
12+
1113
from roslibpy import Service
1214
from roslibpy import ServiceRequest
1315

@@ -30,6 +32,13 @@ def __init__(self, name, service_type, request_class=None, response_class=None,
3032

3133
def call(self, client, request, callback, errback):
3234
def inner_handler(response_msg):
35+
# IronPython sometimes decides it's a good idea to use an old-style class
36+
# to pass the response_msg around, so we need to make sure we turn it into
37+
# a proper ServiceResponse again
38+
# https://github.com/compas-dev/compas_fab/issues/235
39+
is_old_style_class = isinstance(response_msg, types.InstanceType)
40+
if is_old_style_class:
41+
response_msg = dict(response_msg)
3342
response_object = self.response_class.from_msg(response_msg)
3443

3544
# Validate the response if there's a validator function assigned
@@ -39,14 +48,12 @@ def inner_handler(response_msg):
3948
except Exception as e:
4049
errback(RosValidationError(e, response_object))
4150
return
42-
4351
callback(response_object)
4452

4553
if isinstance(request, tuple):
4654
request_msg = self.request_class(*request)
4755
else:
4856
request_msg = self.request_class(**request)
49-
5057
srv = Service(client, self.name, self.type)
5158
srv.call(ServiceRequest(request_msg.msg),
5259
callback=inner_handler, errback=errback)

0 commit comments

Comments
 (0)