backport of PR #1898 to fix #1049 in stable