Address rules by country: switching the feature off changes nothing on Your details #635

Closed
opened 2026-10-01 10:48:33 +00:00 by tiagoagueda · 0 comments
Owner

Found on 2026-09-29 in a read-only review of postulo at 95348908d, following the Address rules by country switch from the policy to the address form.

Related to #147.

Checked again on 2026-10-01 against main at 0a5cad587: still present.

The feature's description ends "Switched off, every address is free-form with neutral labels." The address form never asks the policy, so the switch has no effect on the one page that shows addresses.

  • Where:
    • core/postal.py:114-129 (label_for, warnings_for): the policy is consulted only when a person is passed.
    • core/postal.py:235 (PostalAddressForm._post_clean): warnings_for(self.instance), no person.
    • core/postal.py:237-242 (labels_for_country): label_for(part, country), no person.
    • core/postal.py:288-302 (formset_for): no parameter for the person; called from accounts/views.py:89.
    • plugins/postal_rules/__init__.py:85-91: the description.
    • tests/test_postal_rules.py:216-225 (test_off_is_the_same_path_a_country_with_no_rules_takes): replaces rules_apply and calls the helpers directly with person=user, so it passes without the page honouring the switch.
  • What happens: an administrator switches Address rules by country off for everybody or for one person, or a person switches it off for themselves. On Your details the address rows still read State and ZIP code for a United States address, and still show the "usually needs" notes after a save. Run against the snapshot with postal.rules_apply replaced by a function that records its calls and returns False: a bound PostalAddressForm for a US address returned {'postcode': 'ZIP code', 'municipality': 'Town or city', 'region': 'State'} from labels_for_country(), two notes in country_notes, and rules_apply was consulted 0 times. The only caller that passes a person is the candidate-file importer (resume/candidate.py:911). core/postal.py:132-138 (render), which also honours the switch, has no caller in src.
  • Why it matters: the switch says it does something and does not. #306 is about to make these rules refuse a save; if the form still does not ask the policy, a person who switched the rules off will have addresses refused by them.
  • Fix: give formset_for and PostalAddressForm the person (through form_kwargs), pass it to label_for and warnings_for in labels_for_country and _post_clean, and pass request.user from accounts/views.py. Replace the test with one that goes through the form. #306 is reworking this form; the check belongs in whatever it leaves.

Done when

  • A test in tests/test_postal_rules.py posts the address formset on Your details with the feature switched off for the person and asserts neutral labels and no country_notes; it fails today.
Found on 2026-09-29 in a read-only review of postulo at 95348908d, following the *Address rules by country* switch from the policy to the address form. Related to #147. Checked again on 2026-10-01 against `main` at `0a5cad587`: still present. The feature's description ends "Switched off, every address is free-form with neutral labels." The address form never asks the policy, so the switch has no effect on the one page that shows addresses. - **Where:** - `core/postal.py:114-129` (`label_for`, `warnings_for`): the policy is consulted only when a `person` is passed. - `core/postal.py:235` (`PostalAddressForm._post_clean`): `warnings_for(self.instance)`, no person. - `core/postal.py:237-242` (`labels_for_country`): `label_for(part, country)`, no person. - `core/postal.py:288-302` (`formset_for`): no parameter for the person; called from `accounts/views.py:89`. - `plugins/postal_rules/__init__.py:85-91`: the description. - `tests/test_postal_rules.py:216-225` (`test_off_is_the_same_path_a_country_with_no_rules_takes`): replaces `rules_apply` and calls the helpers directly with `person=user`, so it passes without the page honouring the switch. - **What happens:** an administrator switches *Address rules by country* off for everybody or for one person, or a person switches it off for themselves. On *Your details* the address rows still read *State* and *ZIP code* for a United States address, and still show the "usually needs" notes after a save. Run against the snapshot with `postal.rules_apply` replaced by a function that records its calls and returns `False`: a bound `PostalAddressForm` for a US address returned `{'postcode': 'ZIP code', 'municipality': 'Town or city', 'region': 'State'}` from `labels_for_country()`, two notes in `country_notes`, and `rules_apply` was consulted 0 times. The only caller that passes a person is the candidate-file importer (`resume/candidate.py:911`). `core/postal.py:132-138` (`render`), which also honours the switch, has no caller in `src`. - **Why it matters:** the switch says it does something and does not. #306 is about to make these rules refuse a save; if the form still does not ask the policy, a person who switched the rules off will have addresses refused by them. - **Fix:** give `formset_for` and `PostalAddressForm` the person (through `form_kwargs`), pass it to `label_for` and `warnings_for` in `labels_for_country` and `_post_clean`, and pass `request.user` from `accounts/views.py`. Replace the test with one that goes through the form. #306 is reworking this form; the check belongs in whatever it leaves. ## Done when - A test in `tests/test_postal_rules.py` posts the address formset on *Your details* with the feature switched off for the person and asserts neutral labels and no `country_notes`; it fails today.
tiagoagueda added this to the 0.6.0 milestone 2026-10-01 10:48:33 +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#635
No description provided.