Follow-up to #515 to backport to 6.x