Skip to content

🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!

Return 400 instead of 500 for oversized CSV fields

Omega (QA)c6f2e02c136f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cc4b399..8f9ed76 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,8 @@
- _Files: `frontend/js/components/tagManager.js`_
### Fixed
+- **Oversized CSV fields now return 400 instead of 500:** a single CSV cell over 128KB raised `csv.Error: field larger than field limit`, which fell into the generic import handler as HTTP 500. CSV parse errors now return a clean 400 (`csv_field_too_large`).
+ - _Files: `backend/warranties_routes.py`
- **Total Value card no longer sums across currencies (issue #192):** the `/statistics` and `/statistics/global` endpoints summed `purchase_price` across all currencies into one number while the card displays the user's default-currency symbol. Both now filter to the requesting user's default currency (via a backend symbol→code map mirroring the frontend's `getCurrencyCode()`).
- _Files: `backend/statistics_routes.py`
- **Overlong serial numbers now return 400 instead of 500:** serials over 255 characters crashed with an unhandled DB error on warranty create and update; both now validate and return `serial_number_too_long`.
diff --git a/backend/warranties_routes.py b/backend/warranties_routes.py
index 4453928..b779c82 100644
--- a/backend/warranties_routes.py
+++ b/backend/warranties_routes.py
@@ -1584,6 +1584,12 @@ def import_warranties():
"errors": failed_rows
}), 200
+ except csv.Error as e:
+ if conn:
+ conn.rollback()
+ logger.error(f"CSV parsing error during import: {e}")
+ return jsonify({"error": "CSV file could not be parsed: a field exceeds the maximum allowed size.",
+ "code": "csv_field_too_large"}), 400
except Exception as e:
if conn:
conn.rollback() # Rollback on general error