BUG: Renaming or moving a folder wipes its favourites albums and faces
Is there an existing issue for this?
- [x] I have searched the existing issues
What happened?
When a folder inside an added library folder is renamed or moved in the file explorer PictoPy treats it as a deleted folder plus a brand new one. Every photo in it gets a new id so everything that was attached to the old rows is gone
- favourites are cleared
- the photos drop out of every album they were in
- their faces are deleted and the person disappears from the People page
- the renamed folder comes back with AI tagging turned off so it never gets tagged again
The photo files on disk are fine, only the library data is lost and there is no error or warning anywhere. Renaming or moving a single photo or video does the same thing for that one file
Steps to reproduce
- Add a folder like
Photosthat has a subfolderTripwith a few images - Favourite one of the Trip photos and add the Trip photos to an album
- Rename
Photos/TriptoPhotos/Goa Trip 2026in the file explorer - Wait for the sync then open the album and the favourites
The album shows 0 photos and the favourite is gone. The gallery still shows the photos but they are new rows with new ids
I could reproduce this on dev (a0eb2c9) and on v1.3.0-alpha
Why it happens
- The watcher calls
delete-folderswith the old folder id as soon as a watched subfolder disappears (sync-microservice/app/utils/watcher.py,watcher_util_handle_file_changes) sync_folderinbackend/app/routes/folders.pydeletes the missing child folder and adds the new path as a separate folder- For single files the obsolete image and video cleanup in
backend/app/utils/images.pyandbackend/app/utils/videos.pydeletes the old row and the new path is inserted as a new one
All of these go through ON DELETE CASCADE so album_images faces memories and the rest go with them. #968 which added the watcher expected renames and moves to update the records but right now they get deleted instead
Possible fix
Point the existing rows at the new path instead of deleting and re adding them
- For folders match a missing subfolder to a new one when all of its indexed files are there with the same relative path and size
- For single files match on size and mtime (the same check the rescan already uses) and only when the thumbnails are identical so a different photo can never take over someone else's row
- In the watcher sync the folder that gained something before the folder that lost it so a move between folders gets matched before the old one is cleaned up
I have a working fix with tests on my fork and would like to open a PR for it once this is reviewed
Record
- [x] I agree to follow this project's Code of Conduct
👋 Thanks for opening this issue! The maintainers will review it shortly. Till then, do not open any PR. This is a strict rule we like to follow around here :)
⚠️ Potential Duplicate Issue (Semantic Match)
This issue appears semantically similar to the following issues in AOSSIE-Org/PictoPy:
-
BUG: Filesystem and database become inconsistent when images are deleted externally (#812, closed) https://github.com/AOSSIE-Org/PictoPy/issues/812 Similarity: 65.3%
-
BUG: face data persists after source folder is removed (#569, open) https://github.com/AOSSIE-Org/PictoPy/issues/569 Similarity: 63.9%
-
BUG:Folder Deletion dosen't delete memories that were made from that folder. (#1485, closed) https://github.com/AOSSIE-Org/PictoPy/issues/1485 Similarity: 62.7%
Please review before proceeding.
Link your account with Gitcord
Thanks for opening this issue, @harshvardhanrp!
To receive Discord notifications and contributor tracking for this organization:
- Join Discord: https://discord.gg/hjUhu33uAn
- In Discord, run
/link harshvardhanrp - Paste the verification code into your GitHub bio (or a public gist)
- Click Verify in Discord (or run
/verify-link harshvardhanrp)
Once linked, Gitcord can notify you about assignments, mentions, and more.
— Posted by Gitcord
I am on this issue
@harshvardhanrp can i work on this issue if this hasnt been fixed yet?
Hi @RitikaSen27, thanks for asking! I'm already working on this and have a fix with tests ready on my fork. I'm just waiting for a maintainer to review the issue before opening the PR.
Hi @rahulharpal1603 @rohan-pandeyy, whenever you have a moment could you please take a look at this issue I've already worked out the root cause and have a fix with tests ready on my fork If it looks good, could you please assign it to me so I can open the PR Thank you
Hi @rohan-pandeyy, I've opened PR #1703 for this issue. It has tests and CodeRabbit has approved it. Could you please review it and assign this issue to me when you get time? Thanks