Skip to content

Bug: Config file path is relative to current working directory, not script location #450

Description

@minh-vt

Severity: Medium (silently breaks config persistence when launched from a different directory)

Description

backend/config.py defines the config file path as a relative path:

CONFIG_FILE = "config/config.json"
config = Config()
qconfig.load(CONFIG_FILE, config)

This resolves against the current working directory (CWD), not the script's location. If the user launches the app from anywhere other than the project root, qconfig.load() silently fails to find the file, and qconfig.save() (called when settings change) writes to a wrong location.

Consequences:

  • Settings are never persisted (user changes language → restarts → back to default)
  • Window position is never saved/restored
  • The bug in Issue 1 is indirectly masked because every launch looks like a fresh install

Fix

Use an absolute path resolved from the script's location:

CONFIG_FILE = os.path.join(
    os.path.dirname(os.path.abspath(__file__)), "..", "config", "config.json"
)
config = Config()
qconfig.load(CONFIG_FILE, config)

__file__ resolves to the path of backend/config.py, so .. navigates up to the project root, then into config/config.json. This works regardless of CWD.

(Note: if this is later bundled with PyInstaller, __file__ behavior changes — that would need separate handling with sys._MEIPASS. But for source-code usage, this fix is correct and safe.)

Location

  • backend/config.py line ~100 (the CONFIG_FILE assignment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions