fix(recipe): measurement_interval_minutes e image_path si possono di nuovo azzerare (#37.3)

recipe_editor.html saveRecipe(): i due campi vengono sempre inviati nel
payload (valore o null esplicito), non più omessi quando svuotati.
recipe_service.py _header_fields(): per i due campi (unica eccezione
concordata al confine dei lotti, righe ~37-60) distingue "non inviato" da
"inviato null" con model_fields_set, invece di getattr(...) is not None —
altrimenti un null esplicito veniva scartato allo stesso modo di un campo
assente e il valore restava bloccato per sempre. Gli altri campi header
(name, description, requires_*, allow_manual_input) non toccati.
Test backend in test_recipes.py: TestUpdateRecipeClearNullableFields.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-21 23:05:51 +02:00
parent 72f0cb1f1b
commit 2b59c3ec49
3 changed files with 109 additions and 14 deletions
@@ -556,10 +556,13 @@ function recipeEditor() {
description: this.description.trim(),
};
// Measurement interval
if (this.measurementIntervalMinutes) {
payload.measurement_interval_minutes = parseInt(this.measurementIntervalMinutes, 10);
}
// Measurement interval - always sent, explicit null when cleared
// (#37.3): omitting the key when the field was emptied used to leave
// the old value in place forever, because the backend could not tell
// "not sent" from "cleared".
payload.measurement_interval_minutes = this.measurementIntervalMinutes
? parseInt(this.measurementIntervalMinutes, 10)
: null;
// Rules of measurement. Sent every time, including when false: these are the
// settings an operator gets told about, so turning one off has to travel.
@@ -567,10 +570,8 @@ function recipeEditor() {
payload.requires_serial = !!this.requiresSerial;
payload.allow_manual_input = !!this.allowManualInput;
// Include image_path for preview thumbnail
if (this.currentFilePath) {
payload.image_path = this.currentFilePath;
}
// image_path for preview thumbnail - same null-when-cleared rule (#37.3).
payload.image_path = this.currentFilePath || null;
// Include change notes if editing
if (!this.isNew && this.changeNotes.trim()) {