Skip to content

fix(servicebus): annotate async auto_lock_renewer with aio AutoLockRenewer (#47948)#47998

Merged
EldertGrootenboer merged 4 commits into
mainfrom
fix/servicebus-aio-autolockrenewer-annotation-47948
Jul 10, 2026
Merged

fix(servicebus): annotate async auto_lock_renewer with aio AutoLockRenewer (#47948)#47998
EldertGrootenboer merged 4 commits into
mainfrom
fix/servicebus-aio-autolockrenewer-annotation-47948

Conversation

@EldertGrootenboer

Copy link
Copy Markdown
Member

Fix async auto_lock_renewer annotation (sync → aio AutoLockRenewer)

Fixes #47948

Problem

The async azure.servicebus.aio receiver factory methods —
ServiceBusClient.get_queue_receiver, ServiceBusClient.get_subscription_receiver,
and the async ServiceBusReceiver constructor — annotated the auto_lock_renewer
keyword with the synchronous AutoLockRenewer
(azure.servicebus._common.auto_lock_renewer), contradicting their own docstrings
and the runtime-correct behavior, which require the async
azure.servicebus.aio.AutoLockRenewer.

Static type checkers (pyright / mypy / ty) therefore reject the documented,
runtime-correct usage, forcing a cast() or a suppression at every async call
site. The mismatch is not merely cosmetic: the sync renewer's renewal loop is
thread-based and calls renew_lock() synchronously, whereas the async
receiver/session renew_lock is a coroutine — so the annotated class cannot
drive an async receiver at all.

Fix

  • Repoint the auto_lock_renewer annotation to the async AutoLockRenewer in
    both aio/_servicebus_client_async.py and aio/_servicebus_receiver_async.py.
  • In the client the import moves under TYPE_CHECKING (it was only ever used for
    the annotation — the value is passed through as an instance), with the two
    annotations becoming string forward-refs. This mirrors the receiver's existing
    pattern and avoids a circular import (_async_auto_lock_renewer imports
    ServiceBusReceiver at runtime).
  • Add a type-checked async sample,
    renew_lock_via_receiver_auto_lock_renewer_keyword, that passes the renewer via
    the auto_lock_renewer= keyword. The repo's type_check_samples gate now
    covers this path (previously no sample exercised the keyword), so a regression
    is caught statically.

Verification

  • mypy over the reporter's snippet and over the new sample: errors against
    the pre-fix source (arg-type on the auto_lock_renewer= argument) and passes
    against the fixed source.
  • Runtime import of azure.servicebus.aio is unaffected (annotations are string
    forward-refs; the moved import is TYPE_CHECKING-only).
  • No public runtime behavior change — annotation-only correction plus a sample.

Notes

  • The synchronous client/receiver are unchanged; this is an aio-only correction.
  • Docstrings already referenced ~azure.servicebus.aio.AutoLockRenewer; this
    aligns the annotation to the existing documentation.

…newer

The async ServiceBusClient receiver factory methods (get_queue_receiver,
get_subscription_receiver) and the async ServiceBusReceiver annotated the
auto_lock_renewer keyword with the synchronous AutoLockRenewer
(azure.servicebus._common.auto_lock_renewer), contradicting their own
docstrings and the runtime-correct behavior, which require the async
azure.servicebus.aio.AutoLockRenewer. Static type checkers (pyright/mypy/ty)
rejected the documented usage, forcing a cast() or suppression at every async
call site. The sync renewer is thread-based and cannot drive an async
receiver, so the annotated class was genuinely incompatible.

Repoint the annotation to the async AutoLockRenewer via a TYPE_CHECKING
import + string forward-ref in both files, and add a type-checked async
sample (renew_lock_via_receiver_auto_lock_renewer_keyword) as a static
regression guard so the repo's type_check_samples gate now covers the path.

Fixes #47948

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes a type-annotation mismatch in the async Service Bus client/receiver APIs so that auto_lock_renewer is typed as the async azure.servicebus.aio.AutoLockRenewer (matching docs and runtime behavior), and adds an async sample to ensure the keyword argument path is exercised by static type checking.

Changes:

  • Updated azure.servicebus.aio receiver factory method annotations to reference the async AutoLockRenewer via TYPE_CHECKING + forward refs.
  • Updated async ServiceBusReceiver typing import to the async renewer type.
  • Added an async sample that passes auto_lock_renewer= to the receiver factory as a static regression guard, and documented the new sample scenario.

Reviewed changes

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

File Description
sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py Switches auto_lock_renewer annotations to "AutoLockRenewer" with a TYPE_CHECKING import to avoid runtime circular imports.
sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py Updates the type-checking import of AutoLockRenewer to the async implementation.
sdk/servicebus/azure-servicebus/samples/async_samples/auto_lock_renew_async.py Adds a new async sample function that passes the renewer via auto_lock_renewer= to exercise static typing.
sdk/servicebus/azure-servicebus/CHANGELOG.md Records the bugfix in the Unreleased section.

Comment thread sdk/servicebus/azure-servicebus/samples/async_samples/auto_lock_renew_async.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 4 out of 4 changed files in this pull request and generated 1 comment.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 4 out of 4 changed files in this pull request and generated no new comments.

@EldertGrootenboer EldertGrootenboer marked this pull request as draft July 10, 2026 17:00
@EldertGrootenboer EldertGrootenboer marked this pull request as ready for review July 10, 2026 17:11

@j7nw4r j7nw4r left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@EldertGrootenboer EldertGrootenboer merged commit cffe052 into main Jul 10, 2026
24 checks passed
@EldertGrootenboer EldertGrootenboer deleted the fix/servicebus-aio-autolockrenewer-annotation-47948 branch July 10, 2026 22:43
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.

[ServiceBus] aio client and receiver annotate auto_lock_renewer with the sync AutoLockRenewer class, contradicting their own docstrings

3 participants