-
Notifications
You must be signed in to change notification settings - Fork 535
Open
Description
Description:
Problem:
I've encountered an issue with the Stream-Framework
library's ActivitySerializer
class when using the Pickle protocol 4. The serialization process seems to fail when the serialized data contains a semicolon character, which leads to unexpected behavior.
Code Sample:
def dumps(self, activity):
self.check_type(activity)
activity_time = '%.6f' % datetime_to_epoch(activity.time)
parts = [activity.actor_id, activity.verb.id,
activity.object_id, activity.target_id or 0]
extra_context = activity.extra_context.copy()
pickle_string = ''
if extra_context:
pickle_string = pickle.dumps(activity.extra_context)
if six.PY3:
pickle_string = pickle_string.decode('latin1')
parts += [activity_time, pickle_string]
serialized_activity = ','.join(map(str, parts))
return serialized_activity
Issue Details:
In the above code snippet, when using the Pickle protocol 4, if the activity.extra_context contains a semicolon character, the serialization process breaks. This appears to be due to changes in the Pickle module's behavior between protocol versions 3 and 4.
Steps to Reproduce:
if we do this we get semicolon
pickle.dumps({'actor_type': 'brand', 'description': 'Some Description'})
output: b'\x80\x04\x95;\x00\x00\x00\x00\x00\x00\x00}\x94(\x8c\nactor_type\x94\x8c\x05brand\x94\x8c\x0bdescription\x94\x8c\x10Some Description\x94u.'
But if we do use protocol 3 then no semicolon
pickle.dumps({'actor_type': 'brand', 'description': 'Some Description'}, protocol=3)
output: b'\x80\x03}q\x00(X\n\x00\x00\x00actor_typeq\x01X\x05\x00\x00\x00brandq\x02X\x0b\x00\x00\x00descriptionq\x03X\x10\x00\x00\x00Some Descriptionq\x04u.'
Metadata
Metadata
Assignees
Labels
No labels