#1995 Backport fix and test to maintenance-3.x branch