Skip to content

Commit

Permalink
Fix leader deleted from DB when unowned by country but still active i…
Browse files Browse the repository at this point in the history
…n game (#169)
  • Loading branch information
MichaelMakesGames authored Dec 16, 2024
1 parent 95426dd commit 11597e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion stellarisdashboard/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ class Leader(Base):

leader_id = Column(Integer, primary_key=True)
game_id = Column(ForeignKey(Game.game_id))
country_id = Column(ForeignKey(Country.country_id))
country_id = Column(ForeignKey(Country.country_id), nullable=True)
leader_id_in_game = Column(Integer, index=True)

first_name = Column(String(80))
Expand Down
9 changes: 8 additions & 1 deletion stellarisdashboard/parsing/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,8 +1334,15 @@ def _update_leader_attributes(self, country: datamodel.Country, leader: datamode
leader.gender = leader_gender
leader.species = leader_species
leader.leader_traits = leader_traits
leader.country = country
leader.ethic = ethic

# apparently, setting leader.country = None deletes the entire leader from the DB
# but setting leader.country_id = None is fine
if country is None:
leader.country_id = None
else:
leader.country = country

self._session.add(leader)

def _get_leader_traits(self, leader_dict) -> (str, str):
Expand Down

0 comments on commit 11597e7

Please sign in to comment.