Fix Pydantic error by moving DB_DIR outside of Settings class
- Moved DB_DIR Path definition outside Settings class to fix Pydantic 2.x annotation error - Updated path to use project-specific path rather than /app - Added start.py script to validate app loading generated with BackendIM... (backend.im)
This commit is contained in:
parent
5a8adf1d9c
commit
9586f0c506
@ -1,16 +1,19 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from typing import Optional, ClassVar
|
||||
|
||||
|
||||
# Create DB directory outside of the Settings class
|
||||
DB_DIR = Path("/projects/taskmanagerapi-8e2xek/app/storage/db")
|
||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
API_V1_STR: str = "/api/v1"
|
||||
PROJECT_NAME: str = "Task Manager API"
|
||||
|
||||
|
||||
# Database settings
|
||||
DB_DIR = Path("/app") / "storage" / "db"
|
||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||
|
||||
|
||||
|
||||
settings = Settings()
|
@ -1,14 +1,8 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from pathlib import Path
|
||||
import os
|
||||
from app.core.config import settings
|
||||
|
||||
# Use relative path for development environment
|
||||
BASE_DIR = Path(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
DB_DIR = BASE_DIR / "app" / "storage" / "db"
|
||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||
SQLALCHEMY_DATABASE_URL = settings.DATABASE_URL
|
||||
|
||||
engine = create_engine(
|
||||
SQLALCHEMY_DATABASE_URL,
|
||||
|
14
start.py
Normal file
14
start.py
Normal file
@ -0,0 +1,14 @@
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add the project root to the Python path
|
||||
BASE_DIR = Path(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, str(BASE_DIR))
|
||||
|
||||
# Import the app from main.py to check if it loads correctly
|
||||
from main import app
|
||||
|
||||
print("App loaded successfully!")
|
||||
print(f"App name: {app.title}")
|
||||
print("If you can see this message, the error has been fixed.")
|
Loading…
x
Reference in New Issue
Block a user