Skip to content

Commit 75d2f95

Browse files
committed
All tests now pass for python 3.6
except 1 test -- which is same as python 2.7
1 parent 741726f commit 75d2f95

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

graphql_subscriptions/subscription_manager.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from future import standard_library
22
standard_library.install_aliases()
3-
from builtins import filter
43
from builtins import object
54
from types import FunctionType
65
import pickle
@@ -61,8 +60,10 @@ def wait_and_get_message(self):
6160
gevent.sleep(.001)
6261

6362
def handle_message(self, message):
63+
if isinstance(message['channel'], bytes):
64+
channel = message['channel'].decode()
6465
for sub_id, trigger_map in self.subscriptions.items():
65-
if trigger_map[0] == message['channel']:
66+
if trigger_map[0] == channel:
6667
trigger_map[1](pickle.loads(message['data']))
6768

6869

@@ -141,14 +142,14 @@ def subscribe(self, query, operation_name, callback, variables, context,
141142
'channel_options', {})
142143
filter = trigger_map[trigger_name].get('filter',
143144
lambda arg1, arg2: True)
144-
# TODO: Think about this some more...the Apollo library
145-
# let's all messages through by default, even if
146-
# the users incorrectly uses the setup_funcs (does not
147-
# use 'filter' or 'channel_options' keys); I think it
148-
# would be better to raise an exception here
149145
except AttributeError:
150146
channel_options = {}
151147

148+
# TODO: Think about this some more...the Apollo library
149+
# let's all messages through by default, even if
150+
# the users incorrectly uses the setup_funcs (does not
151+
# use 'filter' or 'channel_options' keys); I think it
152+
# would be better to raise an exception here
152153
def filter(arg1, arg2):
153154
return True
154155

@@ -160,7 +161,7 @@ def context_promise_handler(result):
160161
return context
161162

162163
def filter_func_promise_handler(context):
163-
return Promise.all([context, list(filter(root_value, context))])
164+
return Promise.all([context, filter(root_value, context)])
164165

165166
def context_do_execute_handler(result):
166167
context, do_execute = result

graphql_subscriptions/subscription_transport_ws.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,17 @@ def promised_params_handler(params):
160160
raise TypeError(error)
161161

162162
def params_callback(error, result):
163+
# import ipdb; ipdb.set_trace()
163164
if not error:
164165
self.send_subscription_data(
165166
sub_id, {'data': result.data})
166-
elif error.message:
167+
elif hasattr(error, 'message'):
167168
self.send_subscription_data(
168169
sub_id,
169170
{'errors': [{
170171
'message': error.message
171172
}]})
172-
elif error.errors:
173+
elif hasattr(error, 'errors'):
173174
self.send_subscription_data(
174175
sub_id, {'errors': error.errors})
175176
else:
@@ -188,10 +189,10 @@ def graphql_sub_id_promise_handler(graphql_sub_id):
188189
self.send_subscription_success(sub_id)
189190

190191
def error_catch_handler(e):
191-
if e.errors:
192+
if hasattr(e, 'errors'):
192193
self.send_subscription_fail(
193194
sub_id, {'errors': e.errors})
194-
elif e.message:
195+
elif hasattr(e, 'message'):
195196
self.send_subscription_fail(
196197
sub_id, {'errors': [{
197198
'message': e.message

tests/test_subscription_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def test_calls_the_error_callback_if_context_func_throws_error(sub_mgr):
451451
def callback(err, payload):
452452
try:
453453
assert payload is None
454-
assert err.message == 'context error'
454+
assert str(err) == 'context error'
455455
sub_mgr.pubsub.greenlet.kill()
456456
except AssertionError as e:
457457
sys.exit(e)

0 commit comments

Comments
 (0)