Server settings → Defaults: a language error blanks the form above it, and saving that form then wipes the defaults #494

Closed
opened 2026-10-01 10:47:05 +00:00 by tiagoagueda · 0 comments
Owner

Found on 2026-09-29 in a read-only review of postulo at 95348908d, reading DefaultsView.post and posting an invalid language list in a test.

Checked again on 2026-10-01 against main at 0a5cad587: still present. The code is now at core/server_views.py:581-597 (DefaultsView.post), one line lower and otherwise unchanged.

Defaults holds two forms saved separately: the instance's name and defaults, and the offered languages. When the languages form is refused, the view re-renders the page with the main form bound to the languages POST and to no instance, so the name, tagline, default language and time zone above come back empty, and the name is marked as a required field in error.

  • Where: core/server_views.py:580-596, DefaultsView.post: on the invalid path it sets self.object = None and calls self.get_context_data(languages_form=form). FormMixin.get_context_data then builds the main form from get_form_kwargs(), which binds it to request.POST (carrying none of instance_name, tagline, default_language or default_time_zone) with instance=None.
  • What happens: an administrator unticks the language that is the instance default, or unticks every language, and saves the languages card. Checked: the page comes back with the language error and also <input … name="instance_name" … required aria-invalid="true" …> with no value, and the time zone select on its empty option (<option value="" selected>). If the administrator then types the name again and presses Save on the upper card, the default language and time zone they did not touch are stored blank.
  • Why it matters: a spurious error on a field the person did not edit, blank values where the stored ones should be, and a short path to losing the stored defaults.
  • Fix: on the invalid path load the row and pass an unbound main form explicitly: self.object = self.get_object() and self.get_context_data(form=self.get_form_class()(instance=self.object), languages_form=form).

Done when

  • tests/test_server_settings.py has a test that stores an instance name and a default time zone, posts an invalid language list to Defaults, and finds the stored name in the instance_name input, the stored time zone selected, and no error on the name. It fails today.
Found on 2026-09-29 in a read-only review of postulo at 95348908d, reading `DefaultsView.post` and posting an invalid language list in a test. Checked again on 2026-10-01 against `main` at `0a5cad587`: still present. The code is now at `core/server_views.py:581-597` (`DefaultsView.post`), one line lower and otherwise unchanged. Defaults holds two forms saved separately: the instance's name and defaults, and the offered languages. When the languages form is refused, the view re-renders the page with the main form bound to the languages POST and to no instance, so the name, tagline, default language and time zone above come back empty, and the name is marked as a required field in error. - **Where:** `core/server_views.py:580-596`, `DefaultsView.post`: on the invalid path it sets `self.object = None` and calls `self.get_context_data(languages_form=form)`. `FormMixin.get_context_data` then builds the main form from `get_form_kwargs()`, which binds it to `request.POST` (carrying none of `instance_name`, `tagline`, `default_language` or `default_time_zone`) with `instance=None`. - **What happens:** an administrator unticks the language that is the instance default, or unticks every language, and saves the languages card. Checked: the page comes back with the language error and also `<input … name="instance_name" … required aria-invalid="true" …>` with no value, and the time zone select on its empty option (`<option value="" selected>`). If the administrator then types the name again and presses Save on the upper card, the default language and time zone they did not touch are stored blank. - **Why it matters:** a spurious error on a field the person did not edit, blank values where the stored ones should be, and a short path to losing the stored defaults. - **Fix:** on the invalid path load the row and pass an unbound main form explicitly: `self.object = self.get_object()` and `self.get_context_data(form=self.get_form_class()(instance=self.object), languages_form=form)`. ## Done when - `tests/test_server_settings.py` has a test that stores an instance name and a default time zone, posts an invalid language list to Defaults, and finds the stored name in the `instance_name` input, the stored time zone selected, and no error on the name. It fails today.
tiagoagueda added this to the 0.6.0 milestone 2026-10-01 10:47:05 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Postulo/postulo#494
No description provided.