tenekev / immich-auto-stack

This is a simple, yet highly configurable Python script, dressed as a Docker container, that stacks together photos, based on certain criteria.
GNU Affero General Public License v3.0
29 stars 3 forks source link

Auto-stacking fails when `skip_previous` is `True` #10

Open kvalev opened 2 months ago

kvalev commented 2 months ago

I just setup an immich stack with an auto-stacking sidecar container, but the auto-stacking fails if skip_previous is set to True:

immich-auto-stack-1        | Traceback (most recent call last):
immich-auto-stack-1        |   File "/script/immich_auto_stack.py", line 220, in <module>
immich-auto-stack-1        |     main()
immich-auto-stack-1        |   File "/script/immich_auto_stack.py", line 195, in main
immich-auto-stack-1        |     children_id = [x['id'] for x in stack[1:] if x['stackCount'] == None ]
immich-auto-stack-1        |                                                  ~^^^^^^^^^^^^^^
immich-auto-stack-1        | KeyError: 'stackCount'

I dont know whether stackCount is something that is supposed to come from the immich API or it is some refactoring leftover, but in any case, it fails with the latest immich version

tenekev commented 2 months ago

Could you find out which picture causes this error and provide the API response for it?

stackCount is part of the API response. It should be there always. And there is no deprecation notice.

I'll catch it but I really want to know what could have caused it.

kvalev commented 2 months ago

Could you find out which picture causes this error and provide the API response for it?

stackCount is part of the API response. It should be there always. And there is no deprecation notice.

I'll catch it but I really want to know what could have caused it.

Thanks for the quick response. I ran couple of tests and there really isn't a stackCount field in the API response. I just started with immich so I might be missing something very obvious tho.

Here is the content of x, which should be what the API is returning:

{'id': '397eb2b2-7b3c-4862-a60c-8088f1e820ae', 'deviceAssetId': 'PXL_20240707_084051104.jpg', 'ownerId': '58a7d074-c1d4-4893-bd50-ab0648527566', 'deviceId': 'Library Import', 'libraryId': '1625a8c0-b36c-4753-a2cc-253357fb6b9d', 'type': 'IMAGE', 'originalPath': '/mnt/data/external/2024/2024.07.03-04 - Tirana/PXL_20240707_084051104.jpg', 'originalFileName': 'PXL_20240707_084051104.jpg', 'originalMimeType': 'image/jpeg', 'thumbhash': 'JMYFNQiZZqWYqGc3hp4I13dwegen', 'fileCreatedAt': '2024-07-07T08:40:51.104Z', 'fileModifiedAt': '2024-08-31T00:54:28.702Z', 'localDateTime': '2024-07-07T10:40:51.104Z', 'updatedAt': '2024-08-31T03:46:01.175Z', 'isFavorite': False, 'isArchived': False, 'isTrashed': False, 'duration': '0:00:00.00000', 'livePhotoVideoId': None, 'people': [], 'checksum': 'SrxPVDHHup7Rik8bBgQZRD2+Bh4=', 'isOffline': False, 'hasMetadata': True, 'duplicateId': None, 'resized': True}

I also ran a quick test and it seems none of the assets have this property:

immich = Immich(api_url, api_key)
assets = immich.fetchAssets()
print(any(a for a in assets if 'stackCount' in a))

>>> False
tenekev commented 2 months ago

I think it's another case of poorly documented changes to the stacks functionality. I updated to the latest v1.113.0. The API response differs from the one in the official API docs for the latest version.

But the weird part is that I still have a stack property in my response, even if it's null, while you are missing it altogether.

I'll push a potential fix for it but first I want to see what they say in the docs. The stacks changes are quite big.

kvalev commented 2 months ago

Alright, no pressure. Thanks for looking into this issue!

tenekev commented 2 months ago

Keep an eye on the API responses. Maybe your library uses an old schema? Maybe after an update or two, or even a rescan, the schema will match the current version? Dunno, just thinking in writing.

Ще го оправим 😄

PythonNut commented 2 months ago

I also ran a quick test and it seems none of the assets have this property:

immich = Immich(api_url, api_key)
assets = immich.fetchAssets()
print(any(a for a in assets if 'stackCount' in a))

>>> False

Just as another data point, I am also seeing this on my instance.

tenekev commented 2 months ago

Yup. Also, they have updated the API with the proper schema and docs. There is a whole new Stacks endpoint. I'll go through the changes as soon as I can and implement them.

dwnsdp commented 3 weeks ago

Still getting this error. Logs: /script/immich_auto_stack.py 2024-11-01 14:05:40,814 - INFO - ============== INITIALIZING ============== 2024-11-01 14:05:40,815 - INFO - ⬇️ Fetching assets: 2024-11-01 14:05:40,815 - INFO - Page size: 1000 2024-11-01 14:05:51,977 - INFO - Pages: None 2024-11-01 14:05:51,977 - INFO - Assets: 13197 Traceback (most recent call last): File "/script/immich_auto_stack.py", line 251, in main() File "/script/immich_auto_stack.py", line 225, in main children_id = [x['id'] for x in stack[1:] if x['stackCount'] == None ] ~^^^^^^^^^^^^^^