Strange issue with albumdisambig

Hi! Me again. :wink:

After #3852 was fixed, I am having a strange result with albumdisambig.

A few examples below:

beet ls -f '%asciify{$albumartist}/%if{$original_year,$original_year,$year} - $album%ifdef{albumdisambig, ($albumdisambig),}%ifdef{u_type, [$u_type],}/%right{$disc,1}-$track - $title' album:"The Gereg" track:1

Result: The HU/2019 - The Gereg (deluxe edition)/1-01 - The Gereg

The above command gives me the expected output. I want “deluxe edition” capitalized, so I’ll change the command to this:

beet ls -f '%asciify{$albumartist}/%if{$original_year,$original_year,$year} - $album%ifdef{albumdisambig, (%title{$albumdisambig}),}%ifdef{u_type, [$u_type],}/%right{$disc,1}-$track - $title' album:"The Gereg" track:1

Again, I get the expected result, which is The HU/2019 - The Gereg (Deluxe Edition)/1-01 - The Gereg.

If I try an album that has u_type set, but empty albumdisambig, I get extra (), which is not expected.

beet ls -f '%asciify{$albumartist}/%if{$original_year,$original_year,$year} - $album%ifdef{albumdisambig, (%title{$albumdisambig}),}%ifdef{u_type, [$u_type],}/%right{$disc,1}-$track - $title' album:Nightmother track:1

Result: Wormlight/2021 - Nightmother () [Bandcamp]/1-01 - Nightmother

And if I try an album with empty u_type and empty albumdisambig, I see the same issue with extra () from albumdisambig, but there is no extra [] from u_type.

beet ls -f '%asciify{$albumartist}/%if{$original_year,$original_year,$year} - $album%ifdef{albumdisambig, (%title{$albumdisambig}),}%ifdef{u_type, [$u_type],}/%right{$disc,1}-$track - $title' album:Singularity track:1

Result: Stortregn/2016 - Singularity ()/1-01 - Enlighten Salvation

This leads be to believe the issue is with albumdisambig, but I am not sure why. :slight_smile:

My installation is on Arch Linux:

╰─❯ beet --version
beets version 1.5.0
Python version 3.9.6
plugins: edit, fetchart, importadded, importfeeds, info, inline, lastimport, mbcollection, mbsync, mpdstats, mpdupdate, originquery, playlist, scrub, smartplaylist, types, zero

Thanks for reading!