django-mptt: Using get_root() on TreeQuerySet element inside for loop and output stored in list does not persist outside of for loop

Looking only at your first example, in the shell…

In the loop you’re calling item.get_root(). This “returns the root node”, so that is what is being output to the console.

Then you append item to the list.

So the list is a list of the original items. But it sounds like you want it to be a list of root nodes?

So shouldn’t you be appending item.get_root() to the list instead?