OurchiveIO / ourchive

An easily installable fiction, audio, and image archive package.
GNU General Public License v3.0
7 stars 6 forks source link

"Top tags" with zero uses break the front page #138

Closed bellisk closed 3 months ago

bellisk commented 3 months ago

Describe the bug On my new Ourchive instance, I created a single work with tags and then deleted that work, leaving the tags existing but with zero uses. I was then redirected to the front page, which showed a ZeroDivisionError. Deleting all the tags didn't fix this error. The strange thing is that I certainly didn't have this error originally, when there were no tags in the database at all. I tried dropping the Ourchive database and recreating it (following the Getting Started instructions), but the error persisted.

The problem seems to be that font size for the Top Tags displayed on the front page is calculated by dividing by the highest tag use count, which of course causes a problem when this is 0.

https://github.com/c-e-p/ourchive/blob/48a4b90c2a2b6449215b68d6053d140e1205de16/ourchive_app/frontend/views.py#L30-L43

To Reproduce

  1. Deploy Ourchive to VPS hosting as described in https://docs.getourchive.io/admin-getting-started/
  2. Run with OURCHIVE_DEBUG=True in .env
  3. Create and save a new work with tags
  4. See that the work's tags are displayed on the front page as Top Tags
  5. Delete the work
  6. See that you are redirected to the front page, and that you see an error page for ZeroDivisionError

Expected behavior Deleting a work should not break the display of the front page.

Desktop (please complete the following information):

Hosting Digital Ocean droplet running Ubuntu 22.04.

Additional context Logs from accessing the front page after deleting the only work with tags:

urllib3.connectionpool DEBUG 2024-04-20 08:37:24,548 connectionpool 20982 140278385672256 Starting new HTTP connection (1): example.org:80
urllib3.connectionpool DEBUG 2024-04-20 08:37:24,552 connectionpool 20982 140278385672256 http://example.org:80 "GET /api/tags/top HTTP/1.1" 308 180
urllib3.connectionpool DEBUG 2024-04-20 08:37:24,555 connectionpool 20982 140278385672256 Starting new HTTPS connection (1): example.org:443
urllib3.connectionpool DEBUG 2024-04-20 08:37:24,633 connectionpool 20982 140278385672256 https://example.org:443 "GET /api/tags/top HTTP/1.1" 301 None
urllib3.connectionpool DEBUG 2024-04-20 08:37:24,703 connectionpool 20982 140278385672256 https://example.org:443 "GET /api/tags/top/ HTTP/1.1" 200 2891
django.request ERROR 2024-04-20 08:37:24,867 log 20982 140278385672256 Internal Server Error: /
Traceback (most recent call last):
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/ourchive/ourchive/ourchive_app/frontend/views.py", line 39, in index
    font_size = abs(float(font_size))
ZeroDivisionError: division by zero
bellisk commented 3 months ago

Aha, just saw that this is already fixed in both production and v0.5.5.1, which is why it wasn't breaking for me before. :sweat_smile: I must have switched branches at some point. Closing this!