UEWBot / dipvis

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

NoReverseMatch exception seeding boards for round 3 of Whipping #262

Closed UEWBot closed 1 year ago

UEWBot commented 1 year ago
"POST /tournaments/59/rounds/3/seed_games/ HTTP/1.0" 302 0 "https://diplomacytv.com/tournaments/59/rounds/3/seed_games/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:105.0) Gecko/20100101 Firefox/105.0"
Internal Server Error: /tournaments/59/rounds/3/board_call/
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/ubuntu/dipvis/visualiser/tournament/round_views.py", line 72, in round_simple
    return render(request, 'rounds/%s.html' % template, context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/shortcuts.py", line 19, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 170, in render
    return self._render(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/defaulttags.py", line 214, in render
    nodelist.append(node.render_annotated(context))
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 988, in render
    output = self.filter_expression.resolve(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 671, in resolve
    obj = self.var.resolve(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 796, in resolve
    value = self._resolve_lookup(context)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/template/base.py", line 858, in _resolve_lookup
    current = current()
  File "/home/ubuntu/dipvis/visualiser/tournament/models.py", line 1756, in get_absolute_url
    return reverse('game_detail',
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/urls/base.py", line 86, in reverse
    return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/django/urls/resolvers.py", line 698, in _reverse_with_prefix
    raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'game_detail' with arguments '('59', 'R3GA-Windy-Hill/')' not found. 1 pattern(s) tried: ['tournaments/(?P<tournament_id>[0-9]+)/games/(?P<game_name>[^/]+)/\\Z']
UEWBot commented 1 year ago

So the POST in seed_games() redirected to board_call, which is the success path after creating the Games and GamePlayers. The rendering of the board_call template failed to figure out the game_details URL for the R3GA game. The terminating '/' on the board name is interesting, because that's the one character that doesn't get matched for a game_name.

UEWBot commented 1 year ago

I was able to reproduce this by creating a game with a '/' in the name. validate_game_name() should reject names containing '/', and the various help texts should specify that.

UEWBot commented 1 year ago

There are probably more characters that can’t be used as the last part of a URL. Accented characters come to mind. Maybe we should validate it as a slug or use the valid characters used by urllib.quote() - “Letters, digits, and the characters '_.-~'”