See merge request !3062 (merged) and !3073 (merged)
(cherry picked from commit 330dfed1 and 243086ac)