UEWBot / dipvis

Django-based visualiser for tournaments for the boardgame Diplomacy
GNU General Public License v3.0
7 stars 5 forks source link

Possible redirect loop #177

Closed UEWBot closed 3 years ago

UEWBot commented 3 years ago

If we change the roll call for a Round, it's possible to end up in a redirect loop. Because both seed_games() and get_seven() can redirect to the other, but they use different code to determine whether to do so: In seed_games():

        # Check for a multiple of seven players,
        # allowing for players sitting out or playing multiple games
        player_count = r.roundplayer_set.aggregate(Sum('game_count'))['game_count__sum']
        if (player_count is None) or (player_count % 7) != 0:
            # We need players to sit out or play multiple games
            return HttpResponseRedirect(reverse('get_seven',
                                                args=(tournament_id,
                                                      r.number())))

In get_seven():

    count = r.roundplayer_set.count()
    [...]
    sitters = count % 7
    # If we already have an exact multiple of seven players, go straight to creating games
    if sitters == 0:
        return HttpResponseRedirect(reverse('seed_games',
                                            args=(tournament_id,
                                                  round_num)))
UEWBot commented 3 years ago

This might actually provide an answer to this TODO in roll_call():

                    # Ensure that we have a corresponding RoundPlayer
                    i, created = RoundPlayer.objects.get_or_create(player=p,
                                                                   the_round=r)
                    # TODO Should we set game_count to 1 here?
UEWBot commented 3 years ago

That change does seem to have fixed the problem.

UEWBot commented 3 years ago

See also issues #161 #162 and #169.

UEWBot commented 3 years ago

get_seven no longer redirects to seed_games, so this now cannot occur.