Skip to content

Fix tag caching that causes wrong tags from folders#1295

Open
Jakeler wants to merge 4 commits into
simulot:developfrom
Jakeler:bugfix/1262-folder-as-tags-wrong
Open

Fix tag caching that causes wrong tags from folders#1295
Jakeler wants to merge 4 commits into
simulot:developfrom
Jakeler:bugfix/1262-folder-as-tags-wrong

Conversation

@Jakeler

@Jakeler Jakeler commented Jan 30, 2026

Copy link
Copy Markdown

Fix for #1262

The tags were being cached using t.Name as the cache key. However, t.Name is just the last component of the tag path. When multiple files have tags with the same leaf name but different full paths (e.g., "test/1 dir/same" and "test/2 dir/same"), they would collide in the cache because they both had Name="same".

Solution: Changed the cache key to use t.Value (the full tag path):

if uc.tagsCache.AddIDToCollection(t.Value, t, a.ID) {  // CORRECT!

Testing

  • Added e2e test case Test_FromFolder/folder-as-tags
  • Test expects 4 uploads with 4 different tags (one per file/directory combination), test data is included
  • Added/extended some helper functions to actually check all tag values are applied to the right files

I did run the tests locally, they pass and are an good indicator for this issue. Sometimes the testcase/check fails even though the tags are actually applied, because it depends on immich-server updating the metadata (seems to involve reading the sidecar) fast enough. I don't see any way to wait for background job completion on the api, only to trigger jobs, which happens automatically anyway.
We can split off the last commit if that's a problem, but the precise check is useful to find more tagging issues, like the missing tags from duplicates (#1069).

Jakeler and others added 4 commits January 28, 2026 22:45
When using --folder-as-tags, assets in directories with identical
names at different path levels were incorrectly assigned to the same tag.

The root cause was that the tag cache was using Tag.Name (the leaf node name) as the cache key instead of Tag.Value (the full tag path). This caused collisions when multiple directories had the same name but different parent paths.

Fixes simulot#1262
enhance folder-as-tags tests, checks tags on each file against the expected (instead of just checking if all tags exist)
@Jakeler Jakeler requested a review from simulot as a code owner January 30, 2026 02:12
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

Successfully merging this pull request may close these issues.

1 participant