Thumbnails are rotated twice after a MEDIA_FILE rotate when rebuilt
Summary
After a rotate with save_metadata_to_disk = MEDIA_FILE, _write_orientation_to_disk writes the composed orientation into the file's EXIF but leaves Photo.local_orientation set. Any later thumbnail rebuild then applies pyvips' EXIF auto-rotation plus _apply_local_orientation on top, so the thumbnail comes out rotated twice. A second rotate also composes from a PhotoMetadata.orientation that is stale after the first write.
Found during the #2039 review. Dev never hit it because a thumbnail file that already exists under an unchanged hash is never rebuilt. #2039 sidesteps it by treating photos with local_orientation != 1 as not comparable, which means every byte change on a rotated photo rebuilds its thumbnails (wasted work, no data loss).
Steps to reproduce
- User with
save_metadata_to_disk = MEDIA_FILE. - Rotate a photo in the UI.
- Delete its thumbnail files and trigger a regenerate (or replace the file in place after #2039).
- The rebuilt thumbnail is rotated twice.
Suggested fix
After writing the orientation into the media file, reset local_orientation to 1 and refresh the stored PhotoMetadata.orientation so the next rotate composes from the real value. RotateCharacterizationTest.test_written_value_composes_original_exif_not_local_orientation in api/tests/photos pins the current contract and needs updating alongside. Once fixed, the local_orientation != 1 guard in _picture_verdict (file_handlers.py) can go.
Source: LibrePhotos/librephotos