I’m quite sure this will solve your issue:
https://github.com/discourse/discourse/pull/9161
Will merge it once tests pass.