fix: bot configuration loading from environment variables#131
Merged
JacobCoffee merged 2 commits intomainfrom Nov 23, 2025
Merged
fix: bot configuration loading from environment variables#131JacobCoffee merged 2 commits intomainfrom
JacobCoffee merged 2 commits intomainfrom
Conversation
Changes:
- Removed env_prefix from BotSettings and LogSettings to allow direct env var reading
- Changed load_settings() to use default constructor instead of model_validate({})
- Added explicit validation_alias to fields for clarity
- Removed redundant discord_token field validator that was causing validation errors
- Used Field(...) for required discord_token to satisfy type checker
The issue was that model_validate({}) bypasses environment variable loading,
and the env_prefix="BOT_" was causing Pydantic to look for BOT_DISCORD_TOKEN
instead of DISCORD_TOKEN.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Added comprehensive tests for BotSettings and LogSettings to ensure: - Environment variables are properly loaded - Command prefix is assembled based on environment - Presence URL is assembled correctly - Log settings have appropriate defaults - load_settings() returns correct tuple types 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Sorry @JacobCoffee, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
🚅 Deployed to the byte-pr-131 environment in byte
|
|
Documentation preview will be available shortly at https://jacobcoffee.github.io/byte-docs-preview/131 |
Owner
Author
|
i dont think i agree with this at fucking all but its not my say im just watching :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixed bot service startup failure caused by improper environment variable loading in
BotSettingsandLogSettings.Changes
Configuration Loading Fix (
services/bot/src/byte_bot/config.py):env_prefix="BOT_"fromBotSettingsto allow direct environment variable readingenv_prefix="LOG_"fromLogSettingsfor consistencyload_settings()to use default constructor instead ofmodel_validate({})validation_aliasto critical fields for clarityField(...)for requireddiscord_tokento satisfy type checkerTests (
tests/unit/bot/test_config.py):Root Cause
The
load_settings()function was callingBotSettings.model_validate({})with an empty dictionary, which prevented Pydantic Settings from reading environment variables. Additionally, theenv_prefix="BOT_"was causing Pydantic to look forBOT_DISCORD_TOKENinstead ofDISCORD_TOKEN.Verification
.envfileTest Plan
make ci- all checks passuv run python -c "from byte_bot.config import bot_settings"make run-dev-bot(loads config successfully)🤖 Generated with Claude Code