Telephone and address rows: 31 offered languages that have a flag country start with no country #456

Closed
opened 2026-10-01 10:46:50 +00:00 by tiagoagueda · 0 comments
Owner

Found on 2026-09-29 in a read-only review of postulo at 95348908d, comparing phones.FROM_LANGUAGE with languages.FLAG_COUNTRIES and the languages offered.

Checked again on 2026-10-01 against main at 0a5cad587: still present. Two of the callers are now at accounts/forms.py:367 and jobs/forms.py:618; core/phones.py, core/languages.py and the other callers have not moved, and the same 31 codes come out.

phones.default_country picks the country a new telephone or postal address row starts on, from FROM_LANGUAGE. That map stops at the European Union languages plus Brazilian Portuguese (25 entries), while Postulo now offers 69 languages and FLAG_COUNTRIES already names a country for 31 of the missing ones. Somebody reading Postulo in Ukrainian, Turkish, Norwegian, Icelandic, Serbian, Albanian, Georgian, Armenian, Catalan, Welsh, Afrikaans or isiZulu gets a blank country where an EU reader gets a guess.

  • Where: core/phones.py:291 (FROM_LANGUAGE) and core/phones.py:356 (default_country); core/languages.py:66 (FLAG_COUNTRIES); used by accounts/forms.py:366, accounts/views.py:70 and :85, core/mixins.py:155 and jobs/forms.py:621, and through them core/postal.py:208.
  • What happens: the missing codes with a flag country are af, ak, am, bm, bs, ca, cy, eu, gl, hy, is, ka, kab, lb, mg, mk, nb, nr, ny, rw, sn, so, sq, sr, tr, ts, uk, ve, wo, xh and zu. For them the chooser starts blank; a national number typed without choosing a country goes through combine unchanged, is stored as typed, gets no normalised value and so takes part in no uniqueness check.
  • Why it matters: the two maps are meant to differ only where a language has no single home (the docstring of test_the_two_maps_never_contradict_each_other in tests/test_flags.py says so), but here they differ for languages that plainly have one, and the test only forbids contradictions, not gaps.
  • Fix: keep FROM_LANGUAGE for the cases where the telephone answer should differ from the flag, and make default_country fall back to languages.flag_country(code), taking the country part of a subdivision (ES-CT to ES, GB-WLS to GB) and keeping it only if it is in phones.BY_CODE. Then the entries in FROM_LANGUAGE that merely repeat the flag can go.

Done when

  • tests/test_flags.py asserts that every offered language with a flag country gets a non-empty phones.default_country, which fails today for the 31 codes above.
Found on 2026-09-29 in a read-only review of postulo at 95348908d, comparing `phones.FROM_LANGUAGE` with `languages.FLAG_COUNTRIES` and the languages offered. Checked again on 2026-10-01 against `main` at `0a5cad587`: still present. Two of the callers are now at `accounts/forms.py:367` and `jobs/forms.py:618`; `core/phones.py`, `core/languages.py` and the other callers have not moved, and the same 31 codes come out. `phones.default_country` picks the country a new telephone or postal address row starts on, from `FROM_LANGUAGE`. That map stops at the European Union languages plus Brazilian Portuguese (25 entries), while Postulo now offers 69 languages and `FLAG_COUNTRIES` already names a country for 31 of the missing ones. Somebody reading Postulo in Ukrainian, Turkish, Norwegian, Icelandic, Serbian, Albanian, Georgian, Armenian, Catalan, Welsh, Afrikaans or isiZulu gets a blank country where an EU reader gets a guess. - **Where:** `core/phones.py:291` (`FROM_LANGUAGE`) and `core/phones.py:356` (`default_country`); `core/languages.py:66` (`FLAG_COUNTRIES`); used by `accounts/forms.py:366`, `accounts/views.py:70` and `:85`, `core/mixins.py:155` and `jobs/forms.py:621`, and through them `core/postal.py:208`. - **What happens:** the missing codes with a flag country are `af`, `ak`, `am`, `bm`, `bs`, `ca`, `cy`, `eu`, `gl`, `hy`, `is`, `ka`, `kab`, `lb`, `mg`, `mk`, `nb`, `nr`, `ny`, `rw`, `sn`, `so`, `sq`, `sr`, `tr`, `ts`, `uk`, `ve`, `wo`, `xh` and `zu`. For them the chooser starts blank; a national number typed without choosing a country goes through `combine` unchanged, is stored as typed, gets no `normalised` value and so takes part in no uniqueness check. - **Why it matters:** the two maps are meant to differ only where a language has no single home (the docstring of `test_the_two_maps_never_contradict_each_other` in `tests/test_flags.py` says so), but here they differ for languages that plainly have one, and the test only forbids contradictions, not gaps. - **Fix:** keep `FROM_LANGUAGE` for the cases where the telephone answer should differ from the flag, and make `default_country` fall back to `languages.flag_country(code)`, taking the country part of a subdivision (`ES-CT` to `ES`, `GB-WLS` to `GB`) and keeping it only if it is in `phones.BY_CODE`. Then the entries in `FROM_LANGUAGE` that merely repeat the flag can go. ## Done when - `tests/test_flags.py` asserts that every offered language with a flag country gets a non-empty `phones.default_country`, which fails today for the 31 codes above.
tiagoagueda added this to the 0.6.0 milestone 2026-10-01 10:46:50 +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#456
No description provided.