Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.63k stars 2.84k forks source link

Unable to Pickle Array of Message Objects #12901

Closed dgokeeffe closed 3 years ago

dgokeeffe commented 4 years ago

Describe the bug When attempting to pickle.dump() an array of Message objects a TypeError is raised.

To Reproduce Steps to reproduce the behavior:

  1. Attempt to pickle a Message object

Expected behavior The object is pickled correctly

Screenshots

import pickle
from azure.servicebus import Message

msgs = [Message(body={"test"})]
pickle.dump(msgs, open("./dump", "wb"))
File "stringsource", line 2, in uamqp.c_uamqp.StringValue.__reduce_cython__
TypeError: no default __reduce__ due to non-trivial __cinit__
KieranBrantnerMagee commented 4 years ago

Hey @dgokeeffe

Thanks for bringing this up. From a brief read of the error I have an inkling what's causing this (the core of this library is a C-based AMQP library) and why it might not play well with Pickle. I've put this on our backlog as a feature req and we'll need to look into what would be required to address this.

I will say, without making too many promises, that there is a long-term plan to address the AMQP library situation, but we can see if there is any potential workaround in the interim.

swathipil commented 3 years ago

Thanks for your patience @dgokeeffe! Fix will be out in the next uamqp release.