scidsg / frontpage

A self-hosted, privacy-focused publishing platform for autonomous and independent newsrooms.
https://ddosecrets.news
GNU Affero General Public License v3.0
13 stars 2 forks source link

ValueError when loading articles with empty download size #33

Closed glenn-sorrentino closed 7 months ago

glenn-sorrentino commented 7 months ago

Description

When attempting to load an article with an empty string as the download_size, the application throws a ValueError. This issue occurs due to the application trying to convert an empty string to an integer for formatting the download size.

Steps to Reproduce

  1. Navigate to the article page for an article named "Appin Uncensored" or any article with an empty string as its download_size.
  2. The application throws a ValueError and fails to load the article.

Expected Behavior

The application should handle empty strings for download_size gracefully, allowing the article to load without error.

Actual Behavior

The application throws a ValueError: invalid literal for int() with base 10: '' and fails to load the article.

Possible Fix

Enhance the condition to check not only if article.download_size is not None but also if it is not an empty string before attempting to convert it to an integer. This could prevent the ValueError.

Your Environment

glenn-sorrentino commented 7 months ago

Proposed Changes

This fix addresses the issue where articles with an empty string as their download_size cause a ValueError by trying to convert an empty string to an integer. The modification ensures the conversion and formatting only occur when article.download_size is neither None nor an empty string.

Files Affected

Modifications


# In frontpage/routes.py, within the article view function:

- format_size(int(article.download_size)) if article.download_size is not None else None
+ format_size(int(article.download_size)) if article.download_size not in [None, ''] else None