Contacts: a department typed in different case makes a second team, and the test named for reuse asserts the duplicate #528
Labels
No labels
accessibility
authentication
breaking change
bug
documentation
enhancement
interface
internationalisation
observability
performance
security
tier
1
tier
2
tier
3
tier/4
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Postulo/postulo#528
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found on 2026-09-29 in a read-only review of postulo at
95348908d, reading the contact form and its tests and trying the form against a test database.Checked again on 2026-10-01 against
mainat0a5cad587: still present. The code is now atjobs/forms.py:579-582(the comment onContactForm.new_department) andjobs/forms.py:682-684(theget_or_createinContactForm._save_department);tests/test_departments.py:129-148andcore/importer.py:756-759have not moved.The contact form's department box promises to match a typed name against the company's existing departments "which is how
Industry.namedalready works".Industry.namedmatches by slug, ignoring case and accents._save_departmentmatches the exact string, so "engineering" typed beside an existing "Engineering" makes a second department at the same company. The test that should guard the reuse is named for it and asserts the opposite.jobs/forms.py:582-585(the comment onContactForm.new_department),jobs/forms.py:685-687(ContactForm._save_department:Department.objects.get_or_create(owner=self.user, company_id=contact.company_id, name=name)),tests/test_departments.py:129-148(test_a_name_the_company_already_has_is_reusedends withassert Department.objects.for_user(user).count() == 2, "case differs, so it is a new one")['Engineering', 'engineering']. The importer already matches departments case-insensitively when it attaches one to an application (core/importer.py:756-759), so the two paths disagree about whether these are one team._save_department, look the name up withname__iexactamong the company's departments first and create only when none matches, keeping the spelling first entered (asIndustry.nameddoes). Rename or rewritetest_a_name_the_company_already_has_is_reusedso it asserts one department after typing a different case, and add a test that an identical name reuses the department.Done when
test_a_name_the_company_already_has_is_reusedintests/test_departments.pyassertsDepartment.objects.for_user(user).count() == 1andcontact.department.name == "Engineering"after typing "engineering"; it fails today.