You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
from_env() eagerly evaluates try_from_env() even when caller passes auth= #316
KalshiClient.from_env (and the async counterpart) uses kwargs.setdefault("auth", KalshiAuth.try_from_env()). dict.setdefault evaluates its default unconditionally, so try_from_env() runs every time — including reading KALSHI_KEY_ID + KALSHI_PRIVATE_KEY and calling load_pem_private_key on the result.
A CI container with KALSHI_KEY_ID exported and a stale / truncated KALSHI_PRIVATE_KEY lingering from a previous run cannot be unblocked by passing from_env(auth=KalshiAuth.from_pem(...)) — the eager call still raises KalshiAuthError("Invalid PEM private key: ...") before the explicit auth has a chance to win. Also a minor key-hygiene issue: the env PEM is decoded into a cryptography RSAPrivateKey the caller never asked for and immediately discards.
Apply the same edit to AsyncKalshiClient.from_env. Add a regression test that sets a malformed KALSHI_PRIVATE_KEY in the env, passes auth=<explicit> to from_env, and asserts no KalshiAuthError is raised.
Activity
fix(auth): from_env preserves caller-owned KalshiAuth + lazy env eval (…