I fixed the issue in this PR:
https://github.com/discourse/discourse/pull/17590
It will be merged shortly after review.