error when pickle ServiceBusReceivedMessage object
See original GitHub issue- Package Name: azure-servicebus
- Package Version: 7.8.1
- Operating System: alpine 3.12
- Python Version: 3.8.6
Describe the bug There is an error when trying to pickle the ServiceBusReceivedMessage object. The “prefork” pool (multiprocessing) in celery uses pickle for serialization, and from v5.2 it is not working, see details in https://github.com/celery/celery/issues/7237
To Reproduce It can be reproduced by using the following code:
import os
import json
import pickle
from azure.servicebus import ServiceBusClient, ServiceBusMessage
CONNECTION_STR = "XXX"
QUEUE_NAME = "XXX"
msg = {
"body":"W1tdLCB7ImlucHV0X2lkIjogNH0sIHsiY2FsbGJhY2tzIjogbnVsbCwgImVycmJhY2tzIjogbnVsbCwgImNoYWluIjogbnVsbCwgImNob3JkIjogbnVsbH1d",
"content-encoding":"utf-8",
"content-type":"application/json",
"headers":{
"lang":"py",
"task":"tasks.example_task",
"id":"7c66557d-e4bc-437f-b021-b66dcc39dfdf",
"shadow":None,
"eta":"2021-10-07T02:30:23.764066+00:00",
"expires":None,
"group":None,
"group_index":None,
"retries":1,
"timelimit":[
None,
None
],
"root_id":"7c66557d-e4bc-437f-b021-b66dcc39dfdf",
"parent_id":"7c66557d-e4bc-437f-b021-b66dcc39dfdf",
"argsrepr":"()",
"kwargsrepr":"{'input_id': 4}",
"origin":"gen36@94713e01a9c0",
"ignore_result":1,
"x_correlator":"44a1978d-c869-4173-afe4-da741f0edfb9"
},
"properties":{
"correlation_id":"7c66557d-e4bc-437f-b021-b66dcc39dfdf",
"reply_to":"7b9a3672-2fed-3e9b-8bfd-23ae2397d9ad",
"origin":"gen68@c33d4eef123a",
"delivery_mode":2,
"delivery_info":{
"exchange":"",
"routing_key":"celery_task_queue"
},
"priority":0,
"body_encoding":"base64",
"delivery_tag":"dc83ddb6-8cdc-4413-b88a-06c56cbde90d"
}
}
servicebus_client = ServiceBusClient.from_connection_string(conn_str="XXX")
with servicebus_client:
with servicebus_client.get_queue_sender(QUEUE_NAME) as sender:
# Sending a single message
single_message = ServiceBusMessage(json.dumps(msg))
sender.send_messages(single_message)
with servicebus_client:
receiver = servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME)
with receiver:
received_msgs = receiver.receive_messages(max_message_count=10, max_wait_time=5)
for msg in received_msgs:
print(str(msg))
pickle.dumps(msg)
receiver.complete_message(msg)
print("Receive is done.")
The result is:
Traceback (most recent call last):
File "test_pickle.py", line 40, in <module>
pickle.dumps(msg)
File "stringsource", line 2, in uamqp.c_uamqp.CompositeValue.__reduce_cython__
TypeError: no default __reduce__ due to non-trivial __cinit__
Expected behavior It should works.
Screenshots If applicable, add screenshots to help explain your problem.
Additional context There are several bugs opened in celery and billiard which might be related to this issue: https://github.com/celery/celery/issues/7237 https://github.com/celery/billiard/issues/356
Issue Analytics
- State:
- Created 9 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
pickle — Python object serialization — Python 3.11.1 ...
Error raised when an unpicklable object is encountered by Pickler . It inherits PickleError . Refer to What can be pickled and unpickled?...
Read more >azure.servicebus.ServiceBusReceivedMessage class
Dead letter error description, when the message is received from a deadletter subqueue of an entity. Return type. str. dead_letter_reason. Dead letter reason, ......
Read more >Error when retrieving saved object using pickle - Stack Overflow
Using pickle to save the state of my intermediate model. But when retrieving the saved model the execution ends up in error saying:...
Read more >The Python pickle Module: How to Persist Objects in Python
In this tutorial, you'll learn how you can use the Python pickle module to convert your objects into a stream of bytes that...
Read more >Python 3 Notes: Pickling
On this page: pickle module, pickle.dump(), pickle.load(), cPickle module ... A Python data object can be "pickled" as itself, which then can be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @swathipil , I have updated the code within “To Reproduce” section with the data used. Thank you so much.
Thank you the feedback @IsmaelJS. We will investigate and get back to you asap