After Judaism was founded many python exceptions have shown up. Save attached.
Okay, this one is too weird not to share in detail.
The error is not about Judaism being founded at all. Superficially, China discovers a new tech, among others this triggers a dynamic name check and a stability check. To do this, all Chinese cities need to be iterated. Something weird is happening here: China's city list has two cities, but only one of them is actually a city, the other an invalid value (None). When the stability/dynamic name code tries to do anything with that None value, an error occurs.
How can the game think China has two cities, but one of them isn't really a city? Looking into the save, China only has its capital. I quickly considered the likely reason: you can get the city list from the player itself, or you can get the city from the plot it's on. My get cities by owner function kind of does boths for reasons of... code sharing I think (maybe I need to reconsider this). Analysis shows: the player thinks there is a second city, but the plot it should be on says there shouldn't be a city.
This is weird because, when a city is founded, it should be added to its plot as well to its player, before the game proceeds and anything else can happen. In particular, all of that should happen before China can discover a tech.
Took me a while to figure out how that could possibly make sense. First clue: I realised the city was founded through the "AI China gets cities immediately when it builds a settler" rule. Second clue: the city is added to its plot a little later than it is added to its player. This led to me looking into the code being executed in the meantime and I noticed another thing happening there: the tile the city is on is set to be owned (culture covered) by its owner.
This gave me an idea and I checked the game to confirm: there is indeed a tribal village on the tile before the city gets founded on it. Tribal villages get popped when they are culture covered, and building a city cultured covers its tile before the city gets associated with the plot. The tribal village happened to give China a free tech, triggering the tech discovery code mentioned at the beginning,
before that city is properly assigned to its plot. This could only happen because of the special Chinese autofounding rule because normally, tribal villages cannot be popped in the middle of building a city - the settler would have already popped it when moving into the tile before founding the city.
The solution: make sure to culture cover the tile pre-emptively before founding the city, so all the potential tech related stuff can be resolved earlier.
But the more interesting aspect is that this is the perfect illustration of the pitfalls of software development and the weird corner case you can run into that nobody could ever anticipate. But also, that I am still somewhat responsible for because I am doing something not really anticipated by the game (founding a city without having a unit on the tile) and writing code that is (probably needlessly) vulnerable to this particular error: listing cities requires both the player list and the plot city functionality. Oh what fun.