Modifying a One2Many field via on_change

How to replace the lines of a One2Many?
I saw Cédric’s answer here: Setting data for One2Many field trough an on_change function, so is there a way to delete (delete) the One2Many lines (cleanly) before replacing them with another in an on_change ?

Why not just update the existing one?

Because there is a uniqueness constraint on one of the fields

It is probably a bad idea to modify or create such record with a unique constraint.
Any way I do not understand why Setting data for One2Many field trough an on_change function is not working for you.