Merged PR from John Newbery: [Backport] #19839 and #19842 to v0.20