Hi Paul, I see today that this "bug" is now fixed and will be available via Moodle.org download web page soon. It wasn't clear to me if you were the programmer fixing this bug, or if it was Andrew, Anna, or some of the other Tracker participants. I will say "Thanks." Pass my thanks on to the others who were involved.
Update in this tracker issue suggests the bug will be fixed for Moodle 3.9.4 and 3.10. Depending on your version and update planning, you should be able to solve this for your instance by mid January at the latest.