Fixes a regression from 2bd1bbc42. Thanks Daniel Wiesmann for the report and Tim Graham for the review. Backport of c08f85fd54 from master.
Backport of ad0be620aece4dde2f94383426c284f4afef9fbc from master