Skip to content

Bazarr Fails on Python 3.13+ Due to SQLAlchemy and Removed Modules (imghdr, pipes) #2803

Description

@remanifest

Describe the bug
When running Bazarr with Python 3.13+, the following errors occur due to deprecated or removed modules:

  • SQLAlchemy: The bundled SQLAlchemy library is outdated and fails with the following error due to stricter subclassing checks in Python 3.13+:
    AssertionError: Class <class 'sqlalchemy.sql.elements.SQLCoreOperations'> directly inherits TypingOnly but has additional attributes {'__firstlineno__', '__static_attributes__'}
  • imghdr: The imghdr module has been removed in Python 3.13, causing crashes in deathbycaptcha.
  • pipes.quote: The pipes module has been removed, leading to failures in libfilebot.

These issues prevent Bazarr from starting successfully on systems with Python 3.13+.

To Reproduce

  1. Run Bazarr on a system with Python 3.13 or later.
  2. Start the Bazarr service.
  3. Observe crashes in the logs.

Expected behavior
Bazarr should start without errors and function correctly when running on Python 3.13 or later.

Software:

  • Bazarr: v 1.5.0
  • Radarr v 5.16.3.9541
  • Sonarr v 4.0.11.2680
  • OS: Arch Linux (kernel 6.12.6)
  • Python: v 3.13.1

Additional context
I initially discovered these issues on Bazarr v1.4.5. After updating to v1.5.0, I confirmed the problems persist.

To resolve the issues locally, I applied the following fixes:

  1. SQLAlchemy: The bundled sqlalchemy.util was replaced with the latest version from the system-installed SQLAlchemy:
    cp -R /usr/lib/python3.13/site-packages/sqlalchemy/util/* /usr/lib/python3.13/site-packages/bazarr/libs/sqlalchemy/util/

  2. imghdr:

  • Replaced imghdr.what functionality with python-magic:
import magic

def what(_, img):
    mime = magic.Magic(mime=True)
    img_type = mime.from_buffer(img)
    if img_type.startswith("image/jpeg"):
        return 'jpeg'
    elif img_type.startswith("image/png"):
        return 'png'
    elif img_type.startswith("image/gif"):
        return 'gif'
    return None
  • Saved file as imghdr.py in the custom_libs folder
  • Updated deathbycaptcha.py to import the new what function:
from imghdr import what
  1. Replaced pipes.quote with shlex.quote in main.py located in custom_libs/libfilebot:
from shlex import quote

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