Weird behavior while removing child record using self.remove in ERPNext: v12.9.3 (master)

Hello Guys,

I am stuck with this strange issue for a very long time, any help is highly appreciated.

I have this doctype in older version (ERPNext: 7) which i moved(manually copied the folder and did bench migrate) to version 12. This doctype works fine in the old version but behaves bit weird in the new version.

The doctype looks like the image attached below, basically all it does is when i tick any checkbox in the master record, a corresponding row is added in the child table, when i un-tick a checkbox a corresponding row in the child table gets removed.

It works absolutely fine in the old version. But in the new version, when i un-tick one of the checkboxes, along with the un-ticked component in the child table, next following row also getting deleted and then an erroneous new record gets added at the bottom of the table with field labels as values as shown below.

After checking thoroughly, i figured that the issue happens exactly at the following piece of code from python side which basically removes the list of un-ticked components from the child table.

[self.remove(d) for d in del_list]

And the list del_list contains proper values (i.e. the rows to be deleted). This issue happens only when i call the backend method from client script through And there are no errors in developer console either.

Following is the client side .js code that calls the method:

Following is the python side code:

Has anyone experienced similar issue? I have been stuck with this issue for a very long time. I have tried so many alternatives as mentioned below but the issue remains.

What i tried so far:

  • I have deleted the child doctype and manually created again, but the issue remains.
  • Thought the issue is with self.remove in Python3, so tried other ways of removing elements from the list using pop() and del, still same issue.
  • Commented out all the code following the line [self.remove(d) for d in del_list] to confirm that the issue happens at the exact line mentioned.
  • And several other alternatives


1 Like

We have the same problem with frappe 12.21.1. Not on our own DocType, but on the Items in SalesOrder where we modify them through a hook to before_save.

No idea what exactly is happening here. Whenever this happens you can see an error in the JavaScript console about the grid.

Would love to get a fix or proper workaround for this.

Our own ugly workaround consists of manually setting the idx of the child and triggering a reload of the whole document on each refresh (if we removen an item).