When using --default-key to select a key, if there are multiple matches and the first one isn't suitable, it gives up completely, even though it could have worked.
Attached test case has two keys for bob. Since the first one gpg finds is expired, it ends up signing with the key for Alice, instead of using the second and valid key of Bob.
Using --local-user does find the right key in the same scenario.
Note: gpg < 2.4.4 misleadingly show "No secret key", but that's just the message. It was fixed in 2.4.4 to say "Key expired". (T4704)