Backport a fix supplied by WestGrid to 4.2. It had been only in master for some reason.