This a nice catch. We had another bug in that area: a function was called and the return value was discarded. That was a mistake and I made it use the result, but it turns out that the function is buggy and it does not handle empty results. It was originally introduced in:
https://github.com/discourse/discourse/commit/11ee07093c939940f8d09c36211d0f2d0aa8ca56
and then nudged in:
https://github.com/discourse/discourse/commit/ff4fb9c77119ec7e6b2091078b4ff405b8e5a629
I fixed it in and will be available to update after review: