Skip to content

[BUG] Hardcoded relative avatar upload path breaks in production Docker deployment #746

Description

@vipul674

Description of the Bug

In backend/app/routes/profile.py, the avatar upload path is hardcoded as a relative path:

UPLOAD_DIR = Path("uploads/avatars")
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)

This runs at import time (not application startup). The relative path depends on the current working directory at the moment the module is imported. In production (Docker with gunicorn or uvicorn workers), the CWD may not be what's expected.

Contrast this with how the document upload path is handled:

  • backend/app/config.py: UPLOAD_DIR: str = "./data/uploads" — a configurable setting
  • backend/app/main.py (line ~61): os.makedirs(settings.UPLOAD_DIR, exist_ok=True) — runs properly in the lifespan startup event

The avatar upload path should follow the same pattern: configurable via settings, and created during application startup, not at import time.

Steps to Reproduce

  1. Start the application in Docker using docker compose --profile cpu up --build
  2. Upload an avatar
  3. The file may be written to an unexpected directory (relative to the worker's CWD)
  4. Subsequent requests to serve the avatar may fail with 404 because the path doesn't match

Expected Behavior

Avatar upload directory should be configurable through settings and should be created during application startup (lifespan event), not at module import time.

Affected File

backend/app/routes/profile.py (lines ~16-17)

Suggested Fix

Add AVATAR_UPLOAD_DIR to the Settings model in config.py and use it instead of the hardcoded relative path. Move the directory creation to the application lifespan startup.

GSSoC '26

  • Yes, I am participating in GirlScript Summer of Code and would like to fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gssocGirlScript Summer of Code 2026 issue/PR

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions