Skip to content

feat: Lazily resolve config file & load dotenv earlier#1422

Open
edwinjosechittilappilly wants to merge 2 commits intomainfrom
fix-config-lazy-load
Open

feat: Lazily resolve config file & load dotenv earlier#1422
edwinjosechittilappilly wants to merge 2 commits intomainfrom
fix-config-lazy-load

Conversation

@edwinjosechittilappilly
Copy link
Copy Markdown
Collaborator

Make ConfigManager defer resolving the config file path: store an optional _config_file in init and add a config_file property that lazily imports get_config_file_path and sets the Path on first access. In settings.py, load environment files earlier (load_dotenv and parent dir) and reorder imports so env vars are available before importing config.paths and other config modules; remove duplicate dotenv calls and tidy imports. These changes avoid premature evaluation of paths/configs that depend on environment variables.

Make ConfigManager defer resolving the config file path: store an optional _config_file in __init__ and add a config_file property that lazily imports get_config_file_path and sets the Path on first access. In settings.py, load environment files earlier (load_dotenv and parent dir) and reorder imports so env vars are available before importing config.paths and other config modules; remove duplicate dotenv calls and tidy imports. These changes avoid premature evaluation of paths/configs that depend on environment variables.
Import a module-level logger and add logger.debug calls to each path helper in src/config/paths.py. The change logs the relevant environment variables and computed file paths (including get_config_file_path and get_data_file) to improve visibility when diagnosing configuration issues. No functional behavior of the getters is changed.
@github-actions github-actions bot added backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) enhancement 🔵 New feature or request labels Apr 16, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to prevent premature evaluation of config/path values that depend on environment variables by (a) lazily resolving the config file path in ConfigManager, and (b) loading .env files earlier in settings.py so env vars are available before importing other config modules.

Changes:

  • Make ConfigManager defer resolving the config file path until first access via a config_file property.
  • Move load_dotenv() calls earlier in src/config/settings.py to ensure env vars are available sooner.
  • Add debug logging in src/config/paths.py to surface which OPENRAG_*_PATH env vars are being used.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/config/settings.py Reorders imports and loads dotenv earlier to avoid env-dependent config evaluation happening too soon.
src/config/paths.py Adds logging around env-based path helpers to aid debugging of path resolution.
src/config/config_manager.py Introduces lazy config_file resolution to avoid resolving config paths during initialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/config/settings.py
Comment on lines +11 to +18
from dotenv import load_dotenv
load_dotenv(override=False)
load_dotenv("../", override=False)

from config.paths import get_flows_path
from utils.env_utils import get_env_int, get_env_float

import httpx
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are multiple duplicated imports introduced here (e.g., get_env_int/get_env_float and httpx are imported twice). This will trip linters and makes the import ordering harder to reason about; please deduplicate and keep a single import for each symbol/module.

Suggested change
from dotenv import load_dotenv
load_dotenv(override=False)
load_dotenv("../", override=False)
from config.paths import get_flows_path
from utils.env_utils import get_env_int, get_env_float
import httpx
load_dotenv(override=False)
load_dotenv("../", override=False)
from config.paths import get_flows_path

Copilot uses AI. Check for mistakes.
Comment thread src/config/settings.py
from agentd.patch import patch_openai_with_mcp
from dotenv import load_dotenv

from dotenv import load_dotenv
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

load_dotenv is imported twice in a row. Please remove the duplicate import (keep only one) so the module import section stays clean and deterministic.

Suggested change
from dotenv import load_dotenv

Copilot uses AI. Check for mistakes.
Comment thread src/config/paths.py
Comment on lines +77 to 78
logger.debug(f"get_config_file_path: {os.path.join(get_config_path(), 'config.yaml')}")
return os.path.join(get_config_path(), "config.yaml")
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_config_file_path() currently calls get_config_path() twice (once inside the debug f-string and again for the return). That duplicates env lookups and will also emit duplicate debug logs. Please compute the config dir/path once in a local variable and reuse it for both logging and the return value.

Suggested change
logger.debug(f"get_config_file_path: {os.path.join(get_config_path(), 'config.yaml')}")
return os.path.join(get_config_path(), "config.yaml")
config_path = get_config_path()
logger.debug(f"get_config_file_path: {os.path.join(config_path, 'config.yaml')}")
return os.path.join(config_path, "config.yaml")

Copilot uses AI. Check for mistakes.
Comment thread src/config/paths.py
Comment on lines +102 to 103
logger.debug(f"get_data_file: {os.path.join(get_data_path(), filename)}")
return os.path.join(get_data_path(), filename)
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_data_file() calls get_data_path() twice (once for the debug message and once for the return), which repeats env reads and can produce duplicate debug output. Please store data_path = get_data_path() once and reuse it.

Suggested change
logger.debug(f"get_data_file: {os.path.join(get_data_path(), filename)}")
return os.path.join(get_data_path(), filename)
data_path = get_data_path()
logger.debug(f"get_data_file: {os.path.join(data_path, filename)}")
return os.path.join(data_path, filename)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) enhancement 🔵 New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants