Author iritkatriel
Recipients Christopher Stelma, chris.jerdonek, iritkatriel
Date 2021-01-08.15:41:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This seems to be deliberately done here in order to prevent context cycles from forming:

In your code you are creating a cycle where foo is the context (and cause) for bar which is the context (and cause) of the second time foo is raised. 

If you create a new instance of foo for the second raise then there is no cycle and you get what you expect:

        raise Exception('foo')
    except Exception as foo:
        print("1--", foo, foo.__context__, foo.__cause__)
            raise Exception('bar') from foo
        except Exception as bar:
            print("2--", bar, bar.__context__, bar.__context__.__context__)
            raise Exception('foo2') from bar
except Exception as foo:
    wat = foo

print("3--", wat, wat.__context__, wat.__context__.__context__)
print("4--", wat, wat.__cause__, wat.__cause__.__context__)
print("5--", wat, wat.__cause__, wat.__cause__.__cause__)

Output is:

1-- foo None None
2-- bar foo None
3-- foo2 bar foo
4-- foo2 bar foo
5-- foo2 bar foo

I think the bug is in your code - you can't create an exception chain that contains the same exception instance more than once.
Date User Action Args
2021-01-08 15:41:40iritkatrielsetrecipients: + iritkatriel, chris.jerdonek, Christopher Stelma
2021-01-08 15:41:40iritkatrielsetmessageid: <>
2021-01-08 15:41:40iritkatriellinkissue31213 messages
2021-01-08 15:41:40iritkatrielcreate