GoogleGcpCredentials: Enforce dictionary type
@vprashrex ci sta già lavorando.
Dal 23/9/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Is your feature request related to a problem?
The current typing of GoogleGcpCredentials.sa_key as JsonValue allows for string inputs, leading to runtime failures when the service account key is treated as a string instead of a dictionary. This results in high diagnostic costs and failed batch assessments.
Describe the solution you'd like
Narrow the annotation of sa_key to enforce a dictionary type:
- Change
sa_key: JsonValuetosa_key: dict[str, JsonValue] - This will ensure validation fails at credential-creation time with a clear error, eliminating the need for casting in the code.
- Note that existing string inputs will need to be re-saved as JSON objects to avoid issues.
Original issue
Problem
GoogleGcpCredentials.sa_key is typed JsonValue:
# backend/app/core/providers.py:76
sa_key: JsonValue = Field(description="Service account key JSON")
Pydantic's JsonValue is the union of all JSON value types — str included. A service account key submitted as an escaped JSON string therefore passes validation and is persisted as-is.
The failure surfaces much later, at provider runtime:
# backend/app/core/batch/google_gcp.py:91
creds = build_gcp_sa_credentials(cast(dict[str, Any], creds_model.sa_key))
# backend/app/core/cloud/storage.py:516
def build_gcp_sa_credentials(sa_key: dict[str, Any]) -> service_account.Credentials:
return service_account.Credentials.from_service_account_info(sa_key, scopes=list(GCS_SCOPES))
from_service_account_info calls .keys() on the argument, so a stored string raises:
'str' object has no attribute 'keys'
Impact
A batch assessment run fails with status: FAILED and error: "'str' object has no attribute 'keys'", after all items have already been dispatched. Observed with 9/9 items returning assessment: null. The message gives no hint that the stored credential is malformed, so the cost of diagnosis is high.
The cast(dict[str, Any], ...) at the call site also hides this from pyright — the cast asserts a shape the type system never guaranteed.
Proposed fix
Narrow the annotation so the type system enforces what the consumer requires:
sa_key: dict[str, JsonValue] = Field(description="Service account key JSON")
Validation then fails at credential-creation time with a clear Pydantic error instead of at run time. The cast in google_gcp.py becomes unnecessary and should be dropped.
Notes
- Existing rows holding a string
sa_keywill not be repaired by the type change; they need to be re-saved (or backfilled) with the key as a JSON object. - Masking in
mask_credentials(providers.py:260) already assumes non-string secrets forsa_key, so the dict shape is the one the rest of the code expects.
- Lingua principale
- Python
- Stelle
- 18
- Fork
- 10
- Merge medio
- 2g 23h
- PR unite (30g)
- 13
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ProjectTech4DevAI/kaapi-backend
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
ProjectTech4DevAI/kaapi-backend#269 · 1 commento ·
-
ProjectTech4DevAI/kaapi-backend#1206 · 1 assegnatario ·
-
ProjectTech4DevAI/kaapi-backend#1184 · 1 assegnatario ·
-
ProjectTech4DevAI/kaapi-backend#1183 · 1 assegnatario ·
Tutte le issue di ProjectTech4DevAI/kaapi-backend
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
xinnan-tech/xiaozhi-fde-talk#263 ·
-
rules
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
huggingface/Repo2RLEnv#163 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
huggingface/sentence-transformers#4074 ·
-
comp/dashboard invalid P3
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
NousResearch/hermes-agent#121143 ·