Skip to content

Migrate to Mopidy 4.0 #255

@blacklight

Description

@blacklight

Running this extension currently fails with Mopidy >=4.0:

ERROR    2025-07-06 19:24:18,758 [658836:MainThread] mopidy.__main__
  Extension youtube failed during setup. This might have left the registry in a bad state.
Traceback (most recent call last):
  File "/home/blacklight/git_tree/mopidy/venv/lib/python3.13/site-packages/mopidy/__main__.py", line 158, in main
    extension.setup(registry)
    ~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/home/blacklight/git_tree/mopidy/venv/lib/python3.13/site-packages/mopidy_youtube/__init__.py", line 39, in setup
    from .backend import YouTubeBackend, YouTubeCoreListener
  File "/home/blacklight/git_tree/mopidy/venv/lib/python3.13/site-packages/mopidy_youtube/backend.py", line 10, in <module>
    from mopidy.models import Image, Ref, SearchResult, Track, model_json_decoder
ImportError: cannot import name 'model_json_decoder' from 'mopidy.models' (/home/blacklight/git_tree/mopidy/venv/lib/python3.13/site-packages/mopidy/models/__init__.py)

This is because of the changes in the Mopidy 4.0 models API:

Changes to the data models may affect any Mopidy extension or client.

  • The models are now based on Pydantic data classes, which means:
    • All models fields and the replace() method should work as before, so
      unless your extension modifies or adds models, this should not affect you.
    • Models are now type-checked at runtime. This should help catch bugs early.
  • Since we now use Pydantic to convert data models to and from JSON, the old
    model machinery has been removed. This includes the following:
    • :class:mopidy.models.ImmutableObject -- Not used by Mopidy since v1.0.5 nine
      years ago.
    • :class:mopidy.models.ValidatedImmutableObject -- The old base class for all models.
    • :class:mopidy.models.ModelJSONEncoder
    • :func:mopidy.models.model_json_decoder
    • :class:mopidy.models.fields.Collection
    • :class:mopidy.models.fields.Date
    • :class:mopidy.models.fields.Field
    • :class:mopidy.models.fields.Identifier
    • :class:mopidy.models.fields.Integer
    • :class:mopidy.models.fields.String
    • :class:mopidy.models.fields.URI

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