LoganMeitz / votefinder

GNU General Public License v3.0
2 stars 2 forks source link

Add game fix #30

Closed rjmagley closed 1 year ago

rjmagley commented 1 year ago

Game-adding appears to be working again. After some prodding I believe the core issue was in the Game model, specifically its save method. I can't 100% point at the reasoning for it, but changing from this:

        self.update_counts()

to this:

        try:
            self.update_counts()
        except:
            pass

seems to fix it. The root cause of the error was this (truncated down to the actual root cause):

  File "/srv/vf/votefinder/main/models.py", line 161, in save
    self.update_counts()
  File "/srv/vf/votefinder/main/models.py", line 123, in update_counts
    self.players_count = self.count_players()
  File "/srv/vf/votefinder/main/models.py", line 168, in count_players
    return self.players.filter(spectator=False, moderator=False).count()
  File "/srv/vf/vfvenv/lib/python3.10/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/srv/vf/vfvenv/lib/python3.10/site-packages/django/db/models/fields/related_descriptors.py", line 718, in get_queryset
    raise ValueError(
ValueError: 'Game' instance needs to have a primary key value before this relationship can be used.

I think at some point there was a change to how a newly-created instance of something is saved to the DB, where in the current version it doesn't "have" a primary key until the save operation completes. I could be completely wrong, but it does appear to work for now.

In the process of debugging this, I also started up a debug app to help us test things manually in the future - it should be rigged to be completely inaccessible if the server isn't running in debug mode. I don't know if this is Wise or not, really, so if we scoop it out later I'm not deeply attached. At the time I was imagining a future where fixing this problem would have created lots of broken games that would need to be cleared from the local/testing DB, and I didn't want to have to do it via the Django shell or MySQL Workbench or whatever, but it appears to have been a quick fix, so shrugguy.txt