Thanks for the leg work simon. I have a PR ready with a fix:
https://github.com/discourse/discourse/pull/11773