Compare commits

...

2 Commits

Author SHA1 Message Date
Misaka_Company
a6873ae2ee fix: resolve YAML config path relative to project root
Ensure config/settings.yaml can be found when running from any working
directory by resolving the path relative to the settings.py file location
rather than the current working directory.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-12 09:40:46 +08:00
Misaka_Company
8292de7747 refactor: update database.py to use new config module
Update import statement from app.core.config to config.settings as part
of YAML configuration migration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-12 09:37:52 +08:00
2 changed files with 6 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ from typing import Generator
from sqlalchemy import create_engine from sqlalchemy import create_engine
from sqlalchemy.orm import DeclarativeBase, Session, sessionmaker from sqlalchemy.orm import DeclarativeBase, Session, sessionmaker
from app.core.config import settings from config.settings import settings
engine = create_engine( engine = create_engine(
settings.database_url, settings.database_url,

View File

@@ -45,7 +45,12 @@ class Settings(BaseModel):
def load_settings(config_path: str = "config/settings.yaml") -> Settings: def load_settings(config_path: str = "config/settings.yaml") -> Settings:
"""加载 YAML 配置文件""" """加载 YAML 配置文件"""
# Resolve relative to the project root (where config/ directory exists)
path = Path(config_path) path = Path(config_path)
if not path.is_absolute():
# __file__ is config/settings.py, so parent.parent gives us project root
project_root = Path(__file__).resolve().parent.parent
path = project_root / config_path
if not path.exists(): if not path.exists():
raise FileNotFoundError( raise FileNotFoundError(
f"配置文件不存在: {config_path}\n" f"配置文件不存在: {config_path}\n"