Skip to content

fix: prevent GIGACHAT_* env vars from overriding explicit connector settings#83

Open
temrjan wants to merge 1 commit into
ai-forever:mainfrom
temrjan:fix/env-credentials-override
Open

fix: prevent GIGACHAT_* env vars from overriding explicit connector settings#83
temrjan wants to merge 1 commit into
ai-forever:mainfrom
temrjan:fix/env-credentials-override

Conversation

@temrjan
Copy link
Copy Markdown
Contributor

@temrjan temrjan commented Apr 15, 2026

Summary

Fixes #78 — when GIGA_AGENT_GIGACHAT_FROM_ENV=true and GIGACHAT_CREDENTIALS is set in the environment, the GigaChat SDK (pydantic BaseSettings) picks up env vars even when explicit credentials are provided via connector settings. This breaks login/password (dev) and certificate auth.

Root cause: GigaChat SDK's Settings(BaseSettings) reads GIGACHAT_* env vars for any field not explicitly passed. The SDK constructor filters out None values before creating Settings, so passing credentials=None does not override the env var.

Fix: Temporarily suppress GIGACHAT_* env vars when creating GigaChat client in non-env mode via a context manager, so only explicitly provided settings are used.

Changes

  • gigachat.py: Add _suppress_gigachat_env() context manager, wrap GigaChat() calls in get_api_object() and check_connection() for non-env mode
  • test_registry.py: Add 2 tests — explicit dev and prod settings must not be overridden by env vars

Notes

The issue also mentions certificate auth (cert_file). The current connector doesn't expose a certificate auth type — happy to add it in a follow-up if needed.

…ettings

When GIGA_AGENT_GIGACHAT_FROM_ENV=true and GIGACHAT_CREDENTIALS is set in
the environment, the GigaChat SDK (pydantic BaseSettings) picks up env vars
even when explicit credentials are provided via connector settings.

This breaks login/password (dev) and certificate auth when the user intends
to use a different auth method than what env vars configure.

Fix: suppress GIGACHAT_* env vars when creating GigaChat client in non-env
mode, so only explicitly provided settings are used.

Closes ai-forever#78

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@temrjan
Copy link
Copy Markdown
Contributor Author

temrjan commented Apr 30, 2026

Hi, just a gentle reminder about this PR. Would appreciate a review when you have a moment, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

При заполненных env ломается авторизация гигачата

1 participant