From 82f837e82d8d68b183ef36a43cc04178755213bf Mon Sep 17 00:00:00 2001 From: falaneh Date: Mon, 2 Nov 2026 12:29:28 -0300 Subject: [PATCH] Ignore blank lines in the weight CSV import A blank line in the pasted CSV was reported to the user as a row with an error. --- wger/weight/helpers.py | 3 ++ wger/weight/tests/test_csv_blank_lines.py | 40 +++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 wger/weight/tests/test_csv_blank_lines.py diff --git a/wger/weight/helpers.py b/wger/weight/helpers.py index 60101d5a75..62f72ba9b0 100644 --- a/wger/weight/helpers.py +++ b/wger/weight/helpers.py @@ -58,6 +58,9 @@ def parse_weight_csv(request, cleaned_data): # Process the CSV items first for row in parsed_csv: + if not row: + continue + try: parsed_date = make_aware( datetime.datetime.strptime(row[0], cleaned_data['date_format']) diff --git a/wger/weight/tests/test_csv_blank_lines.py b/wger/weight/tests/test_csv_blank_lines.py new file mode 100644 index 0000000000..4ae9e96340 --- /dev/null +++ b/wger/weight/tests/test_csv_blank_lines.py @@ -0,0 +1,40 @@ +# This file is part of wger Workout Manager. +# +# wger Workout Manager is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# wger Workout Manager is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Workout Manager. If not, see . + +# Standard Library +from types import SimpleNamespace + +# Django +from django.contrib.auth.models import User + +# wger +from wger.core.tests.base_testcase import WgerTestCase +from wger.weight.helpers import parse_weight_csv + + +class WeightCsvBlankLinesTestCase(WgerTestCase): + """ + Test that blank lines in the CSV are not reported as errors + """ + + def test_blank_lines_are_ignored(self): + request = SimpleNamespace(user=User.objects.get(username='test')) + weights, errors = parse_weight_csv( + request, + {'csv_input': '2031-01-01,80\n\n2031-01-02,81\n', 'date_format': '%Y-%m-%d'}, + ) + + self.assertEqual(len(weights), 2) + self.assertEqual(errors, [])