Python Data Structures and Algorithms: issue with DFS code in course

I am working on trying to understand the recursive DFS algo in the Python Data Structures and Algorithms course. Here is the link.

Using this path_graph I get two different answers at different times: one that is correct and the other that is not.

path_graph = {
‘A’: set([‘B’]),
‘B’: set([‘A’, ‘C’]),
‘C’: set([‘B’, ‘D’]),
‘D’: set([‘C’, ‘E’]),
‘E’: set([‘D’])
}

If I call dfs(path_graph, ‘B’, ‘A’) sometimes I get the correct answer of [‘B’, ‘A’] and sometimes I get the incorrect answer of [‘B’, ‘C’, ‘D’, ‘E’, ‘A’]. This makes sense to me since the code given for this implementation of DFS returns the visited list on every recursive call. Since python uses mostly references (basically pointers-but not exactly), it makes sense that if the algo mistakenly goes down the wrong path to begin, then the visited list will contain B, C, D, E before it backtracks and eventually finds A.

My issue with this is that on a previous page it is claimed that this implementation will produce a path from B to A which would be [B,A]. The incorrect answer [B, C, D, E, A] is NOT A PATH IN MY PATH GRAPH AT ALL!!!

So, how is this implementation useful at all? What am I missing here?