Skip to content

Use session.get("language", "en") for safer language access #261

Description

@DogukanUrker

Problem

Throughout the application, session["language"] is accessed directly in many places. If the session is malformed or the language key is missing (e.g., after a session corruption, migration, or edge case), this raises a KeyError that results in a 500 Internal Server Error.

Affected files (partial list):

  • app/utils/delete.py — flash_message calls
  • app/routes/login.py — flash_message calls
  • app/routes/signup.py — flash_message calls
  • app/routes/dashboard.py — flash_message calls
  • app/routes/set_language.py — flash_message calls
  • app/routes/change_username.py — flash_message calls
  • app/routes/change_profile_picture.py — flash_message calls
  • app/routes/verify_user.py — flash_message calls
  • And more...

Requirements

Replace all instances of session["language"] with session.get("language", "en") to gracefully fall back to English when the session language is missing.

This is a low-risk defensive coding improvement that prevents 500 errors in edge cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions