RhetTbull / osxphotos

Python app to work with pictures and associated metadata from Apple Photos on macOS. Also includes a package to provide programmatic access to the Photos library, pictures, and metadata.
MIT License
2.14k stars 99 forks source link

save & load config fail in combination with sidecar-template #1716

Open Syntaxheld opened 3 weeks ago

Syntaxheld commented 3 weeks ago

Describe the bug When using the --sidecar-template option and saving the command to a TOML config file, osxphotos crashes when loading that config file.

To Reproduce Steps to reproduce the behavior:

  1. osxphotos export --directory "{created}{moment?{comma} {moment},}" --album export-test --sidecar-template custom_sidecar_json.mako "{filepath}.json" write_skipped,strip_lines --edited-suffix "-edit" --save-config CONFIG.toml --config-only DIR
  2. osxphotos export --load-config CONFIG.toml DIR
  3. Something went wrong and osxphotos encountered an error: list index out of range

Expected behavior Export command using the config file should work just as well as the one without.

Desktop (please complete the following information):

Additional context If you comment out the sidecar_template line in the toml file (and specify the option on the CLI), it works.

Crashlog attached. osxphotos_crash.log

Syntaxheld commented 3 weeks ago

and the generated config file from the first reproduction step: CONFIG.toml.zip

RhetTbull commented 3 weeks ago

Weird...I'm using the same TOML library to write the config file as I am to read it. I'll take a look to see if I can figure out what is going on.

Syntaxheld commented 3 weeks ago

I have run the file through https://www.toml-lint.com/ ... and it says it's valid. 🤷🏻 So maybe it is an issue in combination with the option parsing?

RhetTbull commented 3 weeks ago

This appears to be a known bug in the toml library used by OSXPhotos. I've confirmed that both tomli and the built in tomllib (which is only available in python 3.11+) do not have this problem and correctly parse the toml file.

I will update the toml code in OSXPhotos to use tomli. In the next release I'll be dropping support for Python 3.9 and adding support for Python 3.13. Once I get to Python 3.11 as the minimum I can then use the built in toml library.

In the meantime you can pass the --sidecar-template option directly on the command line instead of via the config file.

RhetTbull commented 3 weeks ago

@all-contributors please add @Syntaxheld for bug

allcontributors[bot] commented 3 weeks ago

@RhetTbull

I've put up a pull request to add @Syntaxheld! :tada: