fix(jira): use model_validator(after) for jira_token_set + timeout on test
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
FastAPI uses __pydantic_validator__.validate_python() which bypasses model_validate() overrides. Switch to @model_validator(mode='after') which the Pydantic Rust core always calls, so jira_token_set is now correctly derived from the excluded jira_api_token field. Also add a 10s timeout to the jira-test endpoint and better error messages (the Atlassian library's "Expecting value" JSON error was ambiguous). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -295,7 +295,8 @@ def test_jira_connection(
|
||||
|
||||
try:
|
||||
jira = get_user_jira_client(current_user, db)
|
||||
# Lightweight call: get current user info
|
||||
# Lightweight call: get current user info (10 s hard timeout)
|
||||
jira._session.timeout = 10 # type: ignore[attr-defined]
|
||||
myself = jira.myself()
|
||||
return {
|
||||
"status": "ok",
|
||||
@@ -303,10 +304,22 @@ def test_jira_connection(
|
||||
"jira_url": jira_url,
|
||||
}
|
||||
except Exception as exc:
|
||||
raise HTTPException(
|
||||
status_code=502,
|
||||
detail=f"Jira connection failed: {exc}",
|
||||
)
|
||||
err = str(exc)
|
||||
# Translate common Atlassian-library errors into human-readable messages
|
||||
if "Expecting value" in err or "line 1 column 1" in err:
|
||||
detail = (
|
||||
"Jira returned an unexpected response — check that the URL is correct "
|
||||
"and that the account email + API token are valid."
|
||||
)
|
||||
elif "401" in err or "Unauthorized" in err:
|
||||
detail = "Authentication failed (401). Verify your Atlassian email and API token."
|
||||
elif "403" in err or "Forbidden" in err:
|
||||
detail = "Access denied (403). The token may not have permission to access this Jira instance."
|
||||
elif "timed out" in err.lower() or "timeout" in err.lower():
|
||||
detail = "Connection timed out. Check the Jira URL is reachable from the server."
|
||||
else:
|
||||
detail = f"Jira connection failed: {err}"
|
||||
raise HTTPException(status_code=502, detail=detail)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user