backport of #3433
Merge pull request #3438 from jerrinot/fix/dataloss/3.1.8

backport of #3433