[BUG] 500 When Viewing Details Of Certain Games
Bug Description
We have encountered a bug where clicking on certain (niche) games shows an Error 500. This issue is specific to a particular game, "Tsukihime: A Piece of Blue Glass Moon", and occurs when trying to view its details.
To Reproduce
To reproduce this bug, follow these steps:
- Add the game "Tsukihime: A Piece of Blue Glass Moon" to the list.
- Click on the game to see its details.
Expected Behavior
The expected behavior is that the game details should show up as expected.
Screenshots
Error Logs
The error logs are as follows:
[2025-03-12 02:34:43 +0100] [28] [ERROR] Internal Server Error: /details/igdb/game/56057/steinsgate-elite
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/views/decorators/http.py", line 64, in inner
return func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/yamtrack/app/views.py", line 195, in media_details
return render(request, "app/media_details.html", context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/shortcuts.py", line 25, in render
content = loader.render_to_string(template_name, context, request, using=using)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/loader.py", line 62, in render_to_string
return template.render(context, request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/backends/django.py", line 107, in render
return self.template.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 171, in render
return self._render(context)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/test/utils.py", line 114, in instrumented_test_render
return self.nodelist.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 1008, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 969, in render_annotated
return self.render(context)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/loader_tags.py", line 159, in render
return compiled_parent._render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/test/utils.py", line 114, in instrumented_test_render
return self.nodelist.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 1008, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 969, in render_annotated
return self.render(context)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/loader_tags.py", line 65, in render
result = block.nodelist.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 1008, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 969, in render_annotated
return self.render(context)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/defaulttags.py", line 327, in render
return nodelist.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 1008, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 969, in render_annotated
return self.render(context)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/defaulttags.py", line 243, in render
nodelist.append(node.render_annotated(context))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 969, in render_annotated
return self.render(context)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/defaulttags.py", line 327, in render
return nodelist.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 1008, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 969, in render_annotated
return self.render(context)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/loader_tags.py", line 210, in render
return template.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 173, in render
return self._render(context)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/test/utils.py", line 114, in instrumented_test_render
return self.nodelist.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 1008, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 969, in render_annotated
return self.render(context)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 1067, in render
output = self.filter_expression.resolve(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 745, in resolve
new_obj = func(obj, *arg_vals)
^^^^^^^^^^^^^^^^^^^^
File "/yamtrack/app/templatetags/app_tags.py", line 212, in media_url
media_type = media["media_type"] if is_dict else media.media_type
~~~~~^^^^^^^^^^^^^^^^^^
KeyError: 'media_type'
Yamtrack Version
The version of Yamtrack is v0.20.3.
Database
The database used is SQLite.
Possible Causes
Based on the error logs, it appears that the issue is caused by a KeyError in the media_url
function in the app_tags.py
file. This function is trying to access the media_type
key in the media
dictionary, but it does not exist.
Possible Solutions
To fix this issue, we need to ensure that the media
dictionary contains the media_type
key. We can do this by modifying the media_url
function to handle the case where the media_type
key does not exist.
Here is an example of how we can modify the media_url
function to handle this case:
from django.template.defaulttags<br/>
# [BUG] 500 When viewing details of certain games: Q&A
## Q: What is the bug that is causing the Error 500 when viewing details of certain games?
A: The bug is caused by a KeyError in the `media_url` function in the `app_tags.py` file. This function is trying to access the `media_type` key in the `media` dictionary, but it does not exist.
## Q: What is the expected behavior when viewing details of a game?
A: The expected behavior is that the game details should show up as expected.
## Q: What is the current behavior when viewing details of a game that triggers the Error 500?
A: The current behavior is that the game details do not show up, and instead, an Error 500 is displayed.
## Q: What is the version of Yamtrack that is experiencing this issue?
A: The version of Yamtrack is v0.20.3.
## Q: What is the database used by Yamtrack?
A: The database used by Yamtrack is SQLite.
## Q: How can the issue be fixed?
A: The issue can be fixed by modifying the `media_url` function in the `app_tags.py` file to handle the case where the `media_type` key does not exist. This can be done by adding a check to see if the `media_type` key exists in the `media` dictionary before trying to access it.
## Q: What is the impact of this issue on users?
A: The impact of this issue on users is that they will not be able to view the details of certain games, which may cause frustration and inconvenience.
## Q: How can users work around this issue?
A: Users can work around this issue by not trying to view the details of the games that trigger the Error 500. However, this is not a long-term solution and the issue should be fixed as soon as possible.
## Q: How can developers fix this issue?
A: Developers can fix this issue by modifying the `media_url` function in the `app_tags.py` file to handle the case where the `media_type` key does not exist. This can be done by adding a check to see if the `media_type` key exists in the `media` dictionary before trying to access it.
## Q: What are the steps to reproduce this issue?
A: The steps to reproduce this issue are as follows:
1. Add the game "Tsukihime: A Piece of Blue Glass Moon" to the list.
2. Click on the game to see its details.
## Q: What are the error logs for this issue?
A: The error logs for this issue are as follows:
[2025-03-12 02:34:43 +0100] [28] [ERROR] Internal Server Error: /details/igdb/game/56057/steinsgate-elite Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/views/decorators/http.py", line 64, in inner return func(request, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/yamtrack/app/views.py", line 195, in media_details return render(request, "app/media_details.html", context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/shortcuts.py", line 25, in render content = loader.render_to_string(template_name, context, request, using=using) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/loader.py", line 62, in render_to_string return template.render(context, request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/backends/django.py", line 107, in render return self.template.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 171, in render return self._render(context) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/test/utils.py", line 114, in instrumented_test_render return self.nodelist.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 1008, in render return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 969, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/loader_tags.py", line 159, in render return compiled_parent._render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/test/utils.py", line 114, in instrumented_test_render return self.nodelist.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 1008, in render return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 969, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/loader_tags.py", line 65, in render result = block.nodelist.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 1008, in render return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 969, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/defaulttags.py", line 327, in render return nodelist.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 1008, in render return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 969, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/defaulttags.py", line 243, in render nodelist.append(node.render_annotated(context)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 969, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/defaulttags.py", line 327, in render return nodelist.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 1008, in render return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 969, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/loader_tags.py", line 210, in render return template.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 173, in render return self._render(context) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/test/utils.py", line 114, in instrumented_test_render return self.nodelist.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/template/base.py", line 1008, in render return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^