Skip to content

Commit 5440a82

Browse files
Merge pull request #28 from ScalaInc/release-1.0.6
Clone event payloads to prevent cross reference
2 parents bde92f6 + 76c1ed1 commit 5440a82

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

exp_sdk/network.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def __init__(self, sdk, message):
1919
self.time = int(time.time())
2020

2121
@property
22-
def payload(self):
23-
return self._message['payload']
22+
def payload (self):
23+
return json.loads(json.dumps(self._message['payload']))
2424

2525
def respond(self, response):
2626
self._sdk.api.post('/api/networks/current/responses', {'id': self._message['id'], 'channel': self._message['channel'], 'payload': response })

tests/test_network.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def test_queue (self):
1818
channel = self.exp.get_channel(self.generate_name())
1919
listener = channel.listen('m', max_age=1)
2020
channel.broadcast('m', 1)
21+
time.sleep(.1)
2122
channel.broadcast('m', 2)
2223
time.sleep(2)
2324
channel.broadcast('m', 3)
@@ -30,6 +31,18 @@ def test_queue (self):
3031
raise Exception
3132

3233

34+
def test_cloning (self):
35+
channel = self.exp.get_channel(self.generate_name())
36+
listener1 = channel.listen('hi')
37+
listener2 = channel.listen('hi');
38+
channel.broadcast('hi', {});
39+
40+
broadcast = listener1.wait(5)
41+
broadcast.payload['a'] = 1
42+
broadcast2 = listener2.wait(5)
43+
if 'a' in broadcast.payload and broadcast.payload['a'] == 1:
44+
raise Exception
45+
3346

3447

3548
class Test2 (utils.Base):
@@ -78,3 +91,4 @@ def test_listener_timeout (self):
7891
except self.exp_sdk.NetworkError:
7992
return
8093
raise Exception
94+

0 commit comments

Comments
 (0)