Backport PR #4024 to 1.7

Backport fix for gh-4024 to 1.7