mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-24 12:26:01 +08:00
fix: remove retries on connection verification (#12568)
* Remove retries on connection failures, shorten timeouts Faster notice to user on credential failures * set var in place * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -128,12 +128,17 @@ def set_request_context_provider_clients(*, provider_id: UUID, user_id: UUID | s
|
||||
def get_authenticator(instance_url: str, api_key: str) -> IAMAuthenticator | MCSPAuthenticator:
|
||||
"""Return the appropriate authenticator for the Watsonx Orchestrate API."""
|
||||
if ".cloud.ibm.com" in instance_url:
|
||||
return IAMAuthenticator(apikey=api_key, url=WxOAuthURL.IBM_IAM.value)
|
||||
elif ".ibm.com" in instance_url: # noqa: RET505 - explicitness
|
||||
return MCSPAuthenticator(apikey=api_key, url=WxOAuthURL.MCSP.value)
|
||||
authenticator = IAMAuthenticator(apikey=api_key, url=WxOAuthURL.IBM_IAM.value)
|
||||
elif ".ibm.com" in instance_url:
|
||||
authenticator = MCSPAuthenticator(apikey=api_key, url=WxOAuthURL.MCSP.value)
|
||||
else:
|
||||
msg = f"Could not determine authentication scheme for instance URL: {instance_url}"
|
||||
raise AuthSchemeError(message=msg)
|
||||
|
||||
msg = f"Could not determine authentication scheme for instance URL: {instance_url}"
|
||||
raise AuthSchemeError(message=msg)
|
||||
# Use a split (connect, read) timeout so that cold-start TCP/TLS handshakes
|
||||
# fail fast instead of blocking for the SDK's default 60 s.
|
||||
authenticator.token_manager.http_config = {"timeout": (10, 30)}
|
||||
return authenticator
|
||||
|
||||
|
||||
async def resolve_wxo_client_credentials(
|
||||
|
||||
@ -4976,6 +4976,20 @@ def test_get_authenticator_unknown_url():
|
||||
get_authenticator("https://example.com", "test-key")
|
||||
|
||||
|
||||
def test_get_authenticator_sets_http_timeout_on_iam():
|
||||
from langflow.services.adapters.deployment.watsonx_orchestrate.client import get_authenticator
|
||||
|
||||
auth = get_authenticator("https://api.region-foobar.cloud.ibm.com", "test-key")
|
||||
assert auth.token_manager.http_config == {"timeout": (10, 30)}
|
||||
|
||||
|
||||
def test_get_authenticator_sets_http_timeout_on_mcsp():
|
||||
from langflow.services.adapters.deployment.watsonx_orchestrate.client import get_authenticator
|
||||
|
||||
auth = get_authenticator("https://api.wxo.ibm.com", "test-key")
|
||||
assert auth.token_manager.http_config == {"timeout": (10, 30)}
|
||||
|
||||
|
||||
def test_get_authenticator_uses_default_iam_urls_when_unset(monkeypatch):
|
||||
try:
|
||||
with monkeypatch.context() as context:
|
||||
|
||||
@ -12,18 +12,22 @@ jest.mock("@/controllers/API/helpers/constants", () => ({
|
||||
getURL: jest.fn(() => "/api/v1/deployments/providers"),
|
||||
}));
|
||||
|
||||
const mockMutate = jest.fn(
|
||||
// biome-ignore lint/suspicious/noExplicitAny: test mock
|
||||
(_key: any, fn: any, options: any) => ({
|
||||
// biome-ignore lint/suspicious/noExplicitAny: test mock
|
||||
mutate: async (payload: any) => {
|
||||
const result = await fn(payload);
|
||||
options?.onSuccess?.(result);
|
||||
options?.onSettled?.(result);
|
||||
return result;
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
jest.mock("@/controllers/API/services/request-processor", () => ({
|
||||
UseRequestProcessor: jest.fn(() => ({
|
||||
// biome-ignore lint/suspicious/noExplicitAny: test mock
|
||||
mutate: jest.fn((_key: any, fn: any, options: any) => ({
|
||||
// biome-ignore lint/suspicious/noExplicitAny: test mock
|
||||
mutate: async (payload: any) => {
|
||||
const result = await fn(payload);
|
||||
options?.onSuccess?.(result);
|
||||
options?.onSettled?.(result);
|
||||
return result;
|
||||
},
|
||||
})),
|
||||
mutate: mockMutate,
|
||||
queryClient: mockQueryClient,
|
||||
})),
|
||||
}));
|
||||
@ -76,6 +80,13 @@ describe("usePostProviderAccount", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("disables automatic retries", () => {
|
||||
usePostProviderAccount();
|
||||
|
||||
const options = mockMutate.mock.calls[0][2];
|
||||
expect(options.retry).toBe(0);
|
||||
});
|
||||
|
||||
it("returns created provider account", async () => {
|
||||
const created = {
|
||||
id: "prov-1",
|
||||
|
||||
@ -32,6 +32,7 @@ export const usePostProviderAccount: useMutationFunctionType<
|
||||
|
||||
return mutate(["usePostProviderAccount"], fn, {
|
||||
...options,
|
||||
retry: 0,
|
||||
onSuccess: () => {
|
||||
return queryClient.refetchQueries({
|
||||
queryKey: ["useGetProviderAccounts"],
|
||||
|
||||
Reference in New Issue
Block a user