diff --git a/bookwyrm/importers/importer.py b/bookwyrm/importers/importer.py
index a3cfba198..a2641ff11 100644
--- a/bookwyrm/importers/importer.py
+++ b/bookwyrm/importers/importer.py
@@ -36,7 +36,11 @@ class Importer:
def create_job(self, user, csv_file, include_reviews, privacy):
"""check over a csv and creates a database entry for the job"""
csv_reader = csv.DictReader(csv_file, delimiter=self.delimiter)
- rows = enumerate(list(csv_reader))
+ rows = list(csv_reader)
+ if len(rows) < 1:
+ raise ValueError("CSV file is empty")
+ rows = enumerate(rows)
+
job = ImportJob.objects.create(
user=user,
include_reviews=include_reviews,
diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py
index ed0f57839..1a3238a1f 100644
--- a/bookwyrm/settings.py
+++ b/bookwyrm/settings.py
@@ -11,7 +11,7 @@ from django.utils.translation import gettext_lazy as _
env = Env()
env.read_env()
DOMAIN = env("DOMAIN")
-VERSION = "0.5.1"
+VERSION = "0.5.2"
RELEASE_API = env(
"RELEASE_API",
diff --git a/bookwyrm/templates/import/import.html b/bookwyrm/templates/import/import.html
index 141e5671e..325caa92b 100644
--- a/bookwyrm/templates/import/import.html
+++ b/bookwyrm/templates/import/import.html
@@ -8,6 +8,12 @@
{% trans "Import Books" %}
+ {% if invalid %}
+
+ {% trans "Not a valid CSV file" %}
+
+ {% endif %}
+
{% if site.imports_enabled %}
{% if recent_avg_hours or recent_avg_minutes %}
diff --git a/bookwyrm/views/imports/import_data.py b/bookwyrm/views/imports/import_data.py
index 4956bfb7d..f0bb2e698 100644
--- a/bookwyrm/views/imports/import_data.py
+++ b/bookwyrm/views/imports/import_data.py
@@ -11,7 +11,6 @@ from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.utils import timezone
from django.utils.decorators import method_decorator
-from django.utils.translation import gettext_lazy as _
from django.views import View
from bookwyrm import forms, models
@@ -30,7 +29,7 @@ from bookwyrm.utils.cache import get_or_set
class Import(View):
"""import view"""
- def get(self, request):
+ def get(self, request, invalid=False):
"""load import page"""
jobs = models.ImportJob.objects.filter(user=request.user).order_by(
"-created_date"
@@ -43,6 +42,7 @@ class Import(View):
"page_range": paginated.get_elided_page_range(
page.number, on_each_side=2, on_ends=1
),
+ "invalid": invalid,
}
seconds = get_or_set("avg-import-time", get_average_import_time, timeout=86400)
@@ -88,7 +88,7 @@ class Import(View):
privacy,
)
except (UnicodeDecodeError, ValueError, KeyError):
- return HttpResponseBadRequest(_("Not a valid csv file"))
+ return self.get(request, invalid=True)
job.start_job()