Backport to maintenance branch Fix/3.x/issue 3704

Fixes #3704