-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fromfilename: Don't crash if title is missing #5907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a crash in the fromfilename plugin that occurs when trying to import music files where the parsed filename data doesn't contain a title field. The fix prevents a KeyError by using a safe dictionary access method with a default fallback.
- Replace direct dictionary access with
.get()
method to handle missing title fields gracefully - Use empty string as default value when title field is absent from parsed filename data
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
What sort of black magic removed the title from an item in your database? |
Prevents this crash: ``` $ beet import ~/Music/Music/_/[1405]/00.mp3 Traceback (most recent call last): File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/bin/.beet-wrapped", line 9, in <module> sys.exit(main()) ~~~~^^ File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/ui/__init__.py", line 1859, in main _raw_main(args) ~~~~~~~~~^^^^^^ File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/ui/__init__.py", line 1838, in _raw_main subcommand.func(lib, suboptions, subargs) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/ui/commands.py", line 1390, in import_func import_files(lib, byte_paths, query) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^ File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/ui/commands.py", line 1330, in import_files session.run() ~~~~~~~~~~~^^ File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/importer/session.py", line 234, in run pl.run_parallel(QUEUE_SIZE) ~~~~~~~~~~~~~~~^^^^^^^^^^^^ File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/util/pipeline.py", line 471, in run_parallel raise exc_info[1].with_traceback(exc_info[2]) File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/util/pipeline.py", line 336, in run out = self.coro.send(msg) File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/util/pipeline.py", line 219, in coro func(*(args + (task,))) ~~~~^^^^^^^^^^^^^^^^^^^ File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/importer/stages.py", line 141, in lookup_candidates plugins.send("import_task_start", session=session, task=task) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/plugins.py", line 505, in send result = handler(**arguments) File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beets/plugins.py", line 200, in wrapper return func(*args, **kwargs) File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beetsplug/fromfilename.py", line 165, in filename_task apply_matches(d, self._log) ~~~~~~~~~~~~~^^^^^^^^^^^^^^ File "/nix/store/lfv9ns20hz2bg6d44js378vcxjfm9261-beets-2.3.1/lib/python3.13/site-packages/beetsplug/fromfilename.py", line 124, in apply_matches item.title = str(d[item][title_field]) ~~~~~~~^^^^^^^^^^^^^ KeyError: 'title' ```
37728dc
to
c3960a2
Compare
@snejus I'm not sure. I've actually ended up with a couple null rows in my database (i.e. where every property is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just add a note in the changelog and we should be good to go!
Prevents this crash:
To Do
docs/
to describe it.)docs/changelog.rst
to the bottom of one of the lists near the top of the document.)