When Tree is in SELECT_ROW mode, a "Index p_column = -1 is out of bounds (cells.size() = 1)" error is thrown

Godot Version

4.5.1.stable

Question

Here’s a minimal example:

class_name ExampleTree extends Tree

func _ready():
	select_mode = Tree.SELECT_ROW # <-- only on this mode
	var root = create_item()
	create_item(root).set_text(0, "item 1")
	var item2 = create_item(root)
	item2.set_text(0, "item 2")
	create_item(item2).set_text(0, "child")
	item_selected.connect(_on_selected)

func _on_selected():
	var item = get_selected()
	item.collapsed = not item.collapsed #<-- this line causes the error

The code behaves as expected, but this error gets pushed:

E 0:00:04:098   example_tree.gd:15 @ _on_selected(): Index p_column = -1 is out of bounds (cells.size() = 1).
  <C++ Source>  scene/gui/tree.cpp:1307 @ select()
  <Stack Trace> example_tree.gd:15 @ _on_selected()

Is this a bug? I didn’t see anything in the Tree or TreeItem documentation saying that this is bad practice.

I suspect that this issue might be related.