partition_key not showing up in azure.functions.ServiceBusMessage
- Dominant language
- PowerShell
- Stars
- 1.1k
- Forks
- 215
- Avg merge
- 4h 2m
- Merged PRs (30d)
- 1
Description
Originally posted by @dobizz over [here](https://github.com/Azure/azure-sdk-for-python/issues/26715)
- **Package Name**: azure.functions.ServiceBusMessage
- **Package Version**:
```
azure-core==1.25.1
azure-functions==1.11.2
azure-servicebus==7.8.0
```
- **Operating System**: Windows 10 Pro (Build 19044.2006)
- **Python Version**: 3.9.0
**Describe the bug**
When sending messages to a partitioned service bus queue and using a service bus trigger, the `partition_key` of the message is lost or not present.

**To Reproduce**
Steps to reproduce the behavior:
1. Create an azure function with an inbound service bus trigger
2. Send a message to a partitioned service bus queue, specifying the `partition_key`
```python
from azure.servicebus import ServiceBusClient, ServiceBusMessage
def send_single_message(sender):
message = ServiceBusMessage("Single session message", partition_key="2")
sender.send_messages(message)
if __name__ == '__main__':
servicebus_client = ServiceBusClient.from_connection_string(conn_str=CONNECTION_STR, logging_enable=True)
with servicebus_client:
sender = servicebus_client.get_queue_sender(queue_name=SESSION_QUEUE_NAME)
with sender:
send_single_message(sender)
```
4. Examine the received `msg: func.ServiceBusMessage`
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**

**Additional context**
`functions.json`
```
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "msg",
"type": "serviceBusTrigger",
"direction": "in",
"queueName": "partitioned_queue_no_session",
"connection": "AzureServiceBusConnectionString",
"isSessionsEnabled": false
}
]
}
```
`host.json`
```
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.*, 4.0.0)"
},
"extensions": {
"serviceBus": {
"prefetchCount": 0,
"messageHandlerOptions": {
"autoComplete": true,
"maxConcurrentCalls": 1,
"maxAutoRenewDuration": "00:05:00"
},
"sessionHandlerOptions": {
"autoComplete": true,
"messageWaitTimeout": "00:00:30",
"maxAutoRenewDuration": "00:55:00",
"maxConcurrentSessions": 1
},
"batchOptions": {
"maxMessageCount": 1,
"operationTimeout": "00:01:00",
"autoComplete": true
}
}
}
}
```
`partition_key` is present in message if received via
```python
receiver = servicebus_client.get_queue_receiver(queue_name=SESSION_QUEUE_NAME, max_wait_time=5)
with receiver:
for msg in receiver:
print(str(msg))
receiver.complete_message(msg)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.