Skip to content
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

osxphotos sync may get confused with two pics in the Library with different UUIDs but same fingerprint (creating by duplicating pics in Photos) #1641

Closed
oPromessa opened this issue Aug 12, 2024 · 1 comment

Comments

@oPromessa
Copy link
Contributor

Before submitting a bug report, please ensure you are running the most recent version of osxphotos and that the bug is reproducible on the latest version

Yes. In this case using a development branch of 0.68.4. But the official 0.68.4 should have the same behaviour.

Describe the bug
Sync impacts any pics with same fingerprint, even though they may have different UUIDs. The pics may have been generated via Duplicate and then Edited in Mac Photos.

To Reproduce
Steps to reproduce the behavior:
0. Use tests/Test-10.15.7.photoslibrary library.

  1. Select picture "Fritest.jpg" with '_uuid': 'A8266C97-9BAF-4AF4-99F3-0013832869B8'
  2. Add it to a New album, say "SyncIssue"
  3. Run osxphotos sync --export test.db
  4. Remove the album "Syncissue"
  5. Run osxphotos sync --import test.db --set title,description,favorite,albums,location --merge keywords --verbose --verbose --timestamp --report import.sync.json
  6. Go into Photos and you'll see in album "Syncissue" two pics, instead of one. Although with different UUIDs, they have the same fingerprint:
    • '_uuid': 'A8266C97-9BAF-4AF4-99F3-0013832869B8'
    • '_uuid': 'D1D4040D-D141-44E8-93EA-E403D9F63E07',
    • they both have the same 'masterFingerprint': 'AUxIqfurFEEy1m1SphGJRmxID+1g'

Expected behavior
Don't know what else osxphotos could do, or if it even should act any differently as across Libraries and beyond the Fingerprint there isn't additional information osxphotos could work with to math/differentiate pics in this situation.

Screenshots
N/A

Desktop (please complete the following information):

$ sw_vers 
ProductName:		macOS
ProductVersion:		14.6.1
BuildVersion:		23G93
$ osxphotos --version
osxphotos, version 0.68.4
Python 3.11.4 (main, Jul  5 2023, 09:00:44) [Clang 14.0.6 ]
macOS 10.16.0, x86_64

Additional context
Building into sync the location field.

@RhetTbull
Copy link
Owner

RhetTbull commented Aug 12, 2024

This is by design. UUIDs only apply to a specific library on a specific Mac. (And if you use Photos library repair tool, UUIDs may change). Because of this, UUIDs cannot be used to compare assets between libraries. osxphotos sync uses a signature (see photo_signature.py) which in most cases, is the case-normalized filename + the fingerprint (a type of file hash used internally by Photos) to match photos. This is fairly reliable but in the case of true duplicates, will result in multiple matches.

In order to maximize the preservation of metadata during sync, if OSXPhotos finds duplicates during export, the metadata is merged:

# it is possible to have multiple photos with the same fingerprint
# for example, the same photo was imported twice or the photo was duplicated in Photos
# in this case, we need to merge the metadata for the photos with the same fingerprint
# as there is no way to know which photo is the "correct" one
key_to_photos = {}
for photo in photos:
key = photo_signature(photo)
if key in key_to_photos:
key_to_photos[key].append(photo)
else:
key_to_photos[key] = [photo]

During import, any photo matching a signature of a photo in the metadata db gets the metadata applied:

for key, key_photos in key_to_photo.items():
if key in import_db:
# import metadata from import_db
for photo in key_photos:
verbose(
f"Importing metadata for [filename]{photo.original_filename}[/] ([uuid]{photo.uuid}[/])"
)
metadata = import_db[key]
results += import_metadata_for_photo(
photo, metadata, set_, merge, dry_run, verbose
)

Given two identical photos with the same name, there is no possible way OSXPhotos could know what the user's intent was when doing a sync so the code maximizes preservation of data.

osxphotos import faces the same issue when looking for duplicates. In this case, #1374 added --signature option which allows the user to specify a custom signature template to be used for duplicate compare. The primary reason for this is the photo_signature() method used in sync compares filenames as part of the signature but when importing there may be duplicates with different filenames and the user would want to find those. Thus you can specify just the fingerprint or some other combination of metadata. I could add this same option to osxphotos sync but it would not resolve this issue and I'm not sure it's as useful in the context of sync because the user likely thinks of a matching photo for sync purposes as one that has the same name and is binary equivalent, not just "any possible duplicate".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants