[BUG] Service Bus Session ID is not available to Function code

Open
#103 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
azure, python

Research direction

Read azure/functions/servicebus.py around lines 274-275 first and compare how session-enabled messages populate msg.session_id with the nested metadata workaround. Reproduce the Service Bus session queue example, then verify that msg.session_id exposes the SessionId while existing message metadata behavior remains intact.

Written by the indexing model from the issue text.

Description

bug needs-investigation
Investigative information
Please provide the following:

IcM: 283549053 has an impacted function app with relevant detail

Repro steps
  1. Create a Function App that triggers off a Service bus session enabled queue.
Provide the steps required to reproduce the problem:
Expected behavior
Provide a description of the expected behavior.
Actual behavior
Provide a description of the actual behavior observed.
Known workarounds
Provide a description of any known workarounds.

Fetch the session id from the nested field in the message:
msg.metadata["MessageSession"]["SessionId"]

Contents of the requirements.txt file:
Provide the requirements.txt file to help us find out module related issues.

N/A

Related information
Provide any related information
  • Bindings used: Service Bus
def main(msg: func.ServiceBusMessage):
    logging.info('Python ServiceBus queue trigger processed message: %s',
                 msg.get_body().decode('utf-8'))
    logging.info('Python msg.session_id - : %s', msg.metadata["MessageSession"]["SessionId"])
    logging.info('Python msg.session_id1 - : %s', msg.session_id)

Output

[2022-02-09T00:36:58.242Z] Python msg.session_id - : {12229E1-B37B-4D29-AA0A-E367906C206E}
[2022-02-09T00:36:58.242Z] Python msg.session_id1 - : None

The location where library sets session_id.

curl -H "Authorization: SharedAccessSignature sr=SERVICE_BUS.servicebus.windows.net%2FINPUT_QUEUE&sig=XXXXXX&se=YYY&skn=RootManageSharedAccessKey"  \
  -H 'BrokerProperties: {"SessionId": "{12229E1-B37B-4D29-AA0A-E367906C206E}"}' \
  -H "Content-Type: application/json" \
  -d "HelloWorld" \
  -X POST -i "https://servicebus-test-vameru.servicebus.windows.net/myinputqueue/messages\?timeout\=60"

HTTP/1.1 201 Created
Transfer-Encoding: chunked
Content-Type: application/xml; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
Strict-Transport-Security: max-age=31536000
Date: Wed, 09 Feb 2022 00:36:57 GMT

The Complete Metadata

{
    "UserProperties": {},
    "DeliveryCount": 1,
    "LockToken": "fc949e24-410f-4a78-853b-7b8ce125cb99",
    "MessageSession": {
        "LockedUntilUtc": "2022-02-08T22: 30: 52.33697Z",
        "SessionId": "{17729E1-B37B-4D29-AA0A-E367906C206E}",
        "RegisteredPlugins": [],
        "ReceiveMode": 0,
        "PrefetchCount": 0,
        "LastPeekedSequenceNumber": 0,
        "Path": "myinputqueue",
        "OperationTimeout": "00: 01: 00",
        "ServiceBusConnection": {
            "Endpoint": "sb://servicebus-test-vameru.servicebus.windows.net",
            "OperationTimeout": "00:01:00",
            "RetryPolicy": {
                "MinimalBackoff": "00:00:00",
                "MaximumBackoff": "00:00:30",
                "DeltaBackoff": "00:00:03",
                "MaxRetryCount": 5,
                "IsServerBusy": False,
                "ServerBusyExceptionMessage": None
            },
            "TransportType": 0,
            "TokenProvider": {},
            "IsClosedOrClosing": False
        },
        "IsClosedOrClosing": False,
        "OwnsConnection": False,
        "ClientId": "MessageSession27myinputqueue_{17729E1-B37B-4D29-AA0A-E367906C206E}",
        "RetryPolicy": {
            "MinimalBackoff": "00:00:00",
            "MaximumBackoff": "00:00:30",
            "DeltaBackoff": "00:00:03",
            "MaxRetryCount": 5,
            "IsServerBusy": False,
            "ServerBusyExceptionMessage": None
        }
    },
    "ContentType": "application/json",
    "SequenceNumber": 13,
    "MessageReceiver": {
        "LockedUntilUtc": "2022-02-08T22:30:52.33697Z",
        "SessionId": "{17729E1-B37B-4D29-AA0A-E367906C206E}",
        "RegisteredPlugins": [],
        "ReceiveMode": 0,
        "PrefetchCount": 0,
        "LastPeekedSequenceNumber": 0,
        "Path": "myinputqueue",
        "OperationTimeout": "00:01:00",
        "ServiceBusConnection": {
            "Endpoint": "sb://servicebus-test-vameru.servicebus.windows.net",
            "OperationTimeout": "00:01:00",
            "RetryPolicy": {
                "MinimalBackoff": "00:00:00",
                "MaximumBackoff": "00:00:30",
                "DeltaBackoff": "00:00:03",
                "MaxRetryCount": 5,
                "IsServerBusy": False,
                "ServerBusyExceptionMessage": None
            },
            "TransportType": 0,
            "TokenProvider": {},
            "IsClosedOrClosing": False
        },
        "IsClosedOrClosing": False,
        "OwnsConnection": False,
        "ClientId": "MessageSession27myinputqueue_{17729E1-B37B-4D29-AA0A-E367906C206E}",
        "RetryPolicy": {
            "MinimalBackoff": "00:00:00",
            "MaximumBackoff": "00:00:30",
            "DeltaBackoff": "00:00:03",
            "MaxRetryCount": 5,
            "IsServerBusy": False,
            "ServerBusyExceptionMessage": None
        }
    },
    "EnqueuedTimeUtc": "2022-02-08T22:22:19.292Z",
    "ExpiresAtUtc": "2022-02-22T22:22:19.292Z",
    "MessageId": "806c77a2924441fe855697d39647e096"
}
Dominant language
Python
Stars
179
Forks
79
Avg merge
2d 8h
Merged PRs (30d)
2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Azure/azure-functions-python-library

All issues in Azure/azure-functions-python-library

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.