Stock Entry throws error but getting submitted which should not happen

I am facing one issue in Stock Entry. The case is that I am creating stock entry through python code by preparing data with multiple Item Lines (Stock Entry Line) and while submitting the Stock Entry, on the very first item some validation error is coming but along with it stock for that item is getting updated but it should not. Another issue is that it is only updating stock for the first item and stock of the rest items is not getting updated because of the validation.

This is happening with me as well. Can anyone help here? @rohit_w perhaps?

(PS: Sorry @rohit_w for tagging you, but its causing a lot of issues when creating stock entry programmatically)