@@ -4364,8 +4364,11 @@ def test_api_budget_propagated_to_custom_requester_subclass_of_http_requester():
43644364 assert len (custom_requester .api_budget ._policies ) == 1
43654365 policy = custom_requester .api_budget ._policies [0 ]
43664366 assert isinstance (policy , MovingWindowCallRatePolicy )
4367- # Also verify the underlying HttpClient received the same budget
4367+ # Verify the underlying HttpClient AND its LimiterSession both received the same
4368+ # budget: rate-limiting is enforced on the session at send() time, so asserting only
4369+ # on the client field is insufficient to prove the policies are actually active.
43684370 assert custom_requester ._http_client ._api_budget is custom_requester .api_budget
4371+ assert custom_requester ._http_client ._session ._api_budget is custom_requester .api_budget
43694372
43704373
43714374def test_api_budget_propagated_to_custom_requester_that_replaces_http_client ():
@@ -4414,6 +4417,10 @@ def test_api_budget_propagated_to_custom_requester_that_replaces_http_client():
44144417 assert isinstance (custom_requester , HttpRequester )
44154418 assert custom_requester .api_budget is not None
44164419 assert custom_requester ._http_client ._api_budget is custom_requester .api_budget
4420+ # The LimiterSession holds its own reference to the budget (captured at client
4421+ # construction time) and is what actually enforces rate limits on send(). Assert
4422+ # it was synced too, otherwise the injected budget is effectively inert.
4423+ assert custom_requester ._http_client ._session ._api_budget is custom_requester .api_budget
44174424
44184425
44194426def test_api_budget_not_overwriting_non_empty_budget_on_replaced_http_client ():
@@ -4458,6 +4465,13 @@ def test_api_budget_not_overwriting_non_empty_budget_on_replaced_http_client():
44584465 assert custom_requester .api_budget is not None
44594466 assert custom_requester ._http_client ._api_budget is not custom_requester .api_budget
44604467 assert len (custom_requester ._http_client ._api_budget ._policies ) == 1
4468+ # The client's own budget must remain wired into its LimiterSession as well, so
4469+ # the sync step never silently swaps an intentionally-installed budget out from
4470+ # under the active session.
4471+ assert (
4472+ custom_requester ._http_client ._session ._api_budget
4473+ is custom_requester ._http_client ._api_budget
4474+ )
44614475
44624476
44634477def test_api_budget_not_propagated_to_non_http_requester_custom_components ():
0 commit comments