Backport #11912 fix to 4-0-stable

This should be backported to 4-0-stable IMO, but I guess it is to late to 4.0.6 , and is it is not a new regression I would not include it in 4.0.6 , We can merge in 4-0-stable and release this with 4.0.7 .

[fixes #15896]

review @rafaelfranca