Skip to content

feat(servicebus): add list_queue_sessions and list_subscription_sessions#46575

Open
EldertGrootenboer wants to merge 13 commits intoAzure:mainfrom
EldertGrootenboer:fix/servicebus-get-message-sessions
Open

feat(servicebus): add list_queue_sessions and list_subscription_sessions#46575
EldertGrootenboer wants to merge 13 commits intoAzure:mainfrom
EldertGrootenboer:fix/servicebus-get-message-sessions

Conversation

@EldertGrootenboer
Copy link
Copy Markdown

@EldertGrootenboer EldertGrootenboer commented Apr 28, 2026

No description provided.

…lient (Azure#44999)

- Pass **kwargs from __init__ to _build_pipeline() in both sync and async
  ServiceBusAdministrationClient so transport kwargs (connection_verify,
  transport, policies, ssl_context) reach the transport layer
- Add unit tests verifying kwargs forwarding for both sync and async clients
- Matches pattern from Azure#26015 fix for ServiceBusClient and azure-core base
- Add _SessionBrowser and _SessionBrowserAsync for management-only AMQP connections
- Add create_mgmt_client to pyamqp and uamqp transports
- Add create_mgmt_client_async to async pyamqp transport
- Add list_queue_sessions/list_subscription_sessions to sync and async ServiceBusClient
- Handle 404+SessionNotFound as empty result in list_sessions_op handler
- Add live tests for queue sessions, subscription sessions, and updated_since mode
Copilot AI review requested due to automatic review settings April 28, 2026 14:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR exposes the AMQP management com.microsoft:get-message-sessions operation in Track 2 by adding public ServiceBusClient APIs to list session IDs for session-enabled queues and subscriptions (sync + async), plus transport support and tests.

Changes:

  • Added internal “management-only” session browser handlers (sync/async) and wired them into new ServiceBusClient.list_queue_sessions() / list_subscription_sessions() APIs.
  • Added management-client factories for management-only AMQP clients in both pyamqp and uamqp transports (sync/async).
  • Updated mgmt handlers + added tests (live tests for list sessions; unit regression tests for management client kwargs forwarding).

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
sdk/servicebus/azure-servicebus/tests/test_mgmt_client_kwargs.py Adds regression tests ensuring admin client __init__ kwargs are forwarded to _build_pipeline (sync/async).
sdk/servicebus/azure-servicebus/tests/test_list_sessions.py Adds live tests for listing queue/subscription session IDs and updated-since mode.
sdk/servicebus/azure-servicebus/azure/servicebus/management/_management_client.py Forwards **kwargs into _build_pipeline for sync admin client.
sdk/servicebus/azure-servicebus/azure/servicebus/aio/management/_management_client_async.py Forwards **kwargs into _build_pipeline for async admin client.
sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py Adds create_mgmt_client() factory for management-only pyamqp client.
sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_uamqp_transport.py Adds create_mgmt_client() factory for management-only uamqp client.
sdk/servicebus/azure-servicebus/azure/servicebus/aio/_transport/_pyamqp_transport_async.py Adds create_mgmt_client_async() for async management-only pyamqp client.
sdk/servicebus/azure-servicebus/azure/servicebus/_session_browser.py New sync internal handler for management-only session listing.
sdk/servicebus/azure-servicebus/azure/servicebus/aio/_session_browser_async.py New async internal handler for management-only session listing.
sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py Adds public sync list_queue_sessions / list_subscription_sessions APIs.
sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py Adds public async list_queue_sessions / list_subscription_sessions APIs.
sdk/servicebus/azure-servicebus/azure/servicebus/_common/mgmt_handlers.py Adjusts list_sessions_op behavior to return empty list on 404.

Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/_common/mgmt_handlers.py Outdated
Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/aio/_session_browser_async.py Outdated
Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/aio/_session_browser_async.py Outdated
Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/_session_browser.py Outdated
Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/_session_browser.py Outdated
Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/_session_browser.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Comment thread sdk/servicebus/azure-servicebus/tests/test_list_sessions.py Outdated
Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/_common/mgmt_handlers.py Outdated
Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/_session_browser.py Outdated
Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/aio/_session_browser_async.py Outdated
- mgmt_handlers.list_sessions_op: gate the empty-list 404 response on the com.microsoft:message-not-found condition so other 404s (entity not found, auth failures) propagate as errors instead of being silently swallowed.

- _session_browser / _session_browser_async: normalize naive updated_since datetimes to UTC so the wire timestamp is independent of the host timezone (matches how naive datetimes are treated elsewhere in the SDK).

- _session_browser / _session_browser_async: build _auth_uri from the full entity path (including /Subscriptions/<sub>) so SAS auth resolves correctly when listing subscription sessions.

- _session_browser / _session_browser_async: remove unused imports (logging/_LOGGER, BaseHandler in async, Any/Union, _MAX_DATETIME, _amqp_timestamp_value).

- _servicebus_client.list_queue_sessions / list_subscription_sessions: drop the forward-reference quotes around datetime so the import is actually used (matches the async client style).

- tests/test_list_sessions.py: remove the unused _logger setup and its logging/get_logger imports.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Add 'timeout > 0' validation to ServiceBusClient.list_queue_sessions, list_subscription_sessions and their async counterparts. Matches the existing validation pattern used by sender/receiver/session operations across the SDK.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.

- Add 'pylint:disable=do-not-import-asyncio' on the asyncio import in _session_browser_async.py to match every other async module in this package.

- Use str keys ('last-updated-time', 'skip', 'top') in the get-message-sessions request body to match the dict[str, Any] signature of _mgmt_request_response_with_retry, fixing two new mypy errors. The pyamqp mgmt layer encodes string keys to bytes on the wire, so behavior is unchanged.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Comment thread sdk/servicebus/azure-servicebus/tests/test_list_sessions.py
…ests

- tests/test_list_sessions.py: add list_subscription_sessions empty + updated_since coverage so the topic/subscription entity path is exercised in both wire modes.

- tests/async_tests/test_list_sessions_async.py: new module covering the _SessionBrowserAsync path (sync parity: queue + subscription, active / empty / updated_since).
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.

Comment thread sdk/servicebus/azure-servicebus/tests/test_list_sessions.py Outdated
Comment thread sdk/servicebus/azure-servicebus/tests/async_tests/test_list_sessions_async.py Outdated
Comment thread sdk/servicebus/azure-servicebus/tests/async_tests/test_list_sessions_async.py Outdated
Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py Outdated
Comment thread sdk/servicebus/azure-servicebus/tests/test_list_sessions.py Outdated
All four updated_since live tests (sync + async, queue + subscription) now use 'datetime.now(timezone.utc) - timedelta(minutes=1)' as the boundary so client/server clock skew can't push the freshly-sent session past the cutoff and cause flakes.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Replace the legacy '# type:' return comment with explicit '-> List[str]' annotations on list_queue_sessions and list_subscription_sessions in both the sync and async ServiceBusClient. Matches other modern public APIs and surfaces the return type to type checkers and IDE tooling.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

The previous docstring said 'sessions whose state was updated' which only matches the user-set state via SetState. The wire-level get-message-sessions operation actually returns sessions whose last update (state change OR message activity) is after the cutoff. Updated the docstrings on the four public methods and on the internal _SessionBrowser/_SessionBrowserAsync.list_sessions to reflect the actual behavior.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

_SessionBrowserAsync calls self._amqp_transport.create_mgmt_client_async(...) but the uamqp async transport never exposed it, so list_queue_sessions / list_subscription_sessions on the async client would AttributeError when uamqp_transport=True. Added the factory mirroring the sync UamqpTransport.create_mgmt_client implementation.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Comment thread sdk/servicebus/azure-servicebus/tests/test_list_sessions.py Outdated
Comment thread sdk/servicebus/azure-servicebus/tests/async_tests/test_list_sessions_async.py Outdated
Comment thread sdk/servicebus/azure-servicebus/azure/servicebus/_transport/_pyamqp_transport.py Outdated
- _pyamqp_transport.py: correct the create_mgmt_client docstring to reference azure.servicebus._common._configuration.Configuration (the configuration class lives in the _common subpackage; the previous path was wrong and broke Sphinx cross-references).

- tests/test_list_sessions.py and tests/async_tests/test_list_sessions_async.py: reorder imports so stdlib (uuid, datetime) comes before third-party (pytest), matching pylint expectations and the rest of the test suite.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.

- _create_session_browser (sync + async): expand stub docstring with params, return, and rtype to satisfy docstring-missing-* checks.

- create_mgmt_client / create_mgmt_client_async (4 transport variants): add docstring-keyword-should-match-keyword-only disable, mirroring the existing pattern on create_send_client where the keyword-only args are passed through **kwargs.

- _transport/_uamqp_transport.py: hoist 'AMQPClient' to the module-level uamqp import block so create_mgmt_client doesn't trip used-before-assignment.

- _transport/_pyamqp_transport.py: drop the redundant TYPE_CHECKING-only import of AMQPClient (already imported at module level for runtime use).

- aio/_transport/_pyamqp_transport_async.py: import AMQPClientAsync directly from ..._pyamqp.aio (it's exported there) instead of the aliased _client_async import; remove the redundant TYPE_CHECKING import; use AMQPClientAsync uniformly.

- aio/_servicebus_client_async.py: extend the existing client-method-missing-tracing-decorator disable to cover the -async variant (matches the sync-side disable already in this module).
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants