Contacts: moving a contact who has a department to another company, or to none, answers 500 #527
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#527
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 againstContact.cleanand posting it in a test.Checked again on 2026-10-01 against
mainat0a5cad587: still present. The code is now atjobs/models.py:649-655(Contact.clean) andjobs/forms.py:593(ContactForm.Meta.fields),jobs/forms.py:639-646(ContactForm.scope_querysets) andjobs/forms.py:670-687(ContactForm._save_department);jobs/views.py:724has not moved.A contact who is in a department cannot be given another company, or no company, through the contact form: the save crashes with a 500. The model refuses a department that belongs to a different company, keyed on a field the form does not have, and the form only reassigns the department after it has saved.
jobs/models.py:646-652(Contact.clean);jobs/forms.py:596(ContactForm.Meta.fields, nodepartment);jobs/forms.py:642-649(ContactForm.scope_querysets);jobs/forms.py:673-690(ContactForm._save_department, which runs only aftersave); reached fromContactUpdateView(jobs/views.py:724).ModelForm._post_cleansets the new company on the instance and runsContact.clean, which still sees A's department and raisesValidationError({"department": ...}).ContactFormhas nodepartmentfield, so Django'sadd_errorraisesValueError: 'ContactForm' has no field named 'department'.and the request answers 500. It happens whatever is typed in the Department box, with Employers with a structure on or off: all eight combinations of {on, off} × {department typed, left blank} × {company B, no company} raise in the snapshot.ContactForm, before the model is validated (an override of_post_clean, orclean), drop the old department from the instance when the company has changed or been cleared, so_save_departmentattaches or creates the right one at the new company afterwards. Independently, a model error about a field the form does not render should land on a field it does: raise the mismatch oncompany(or as a non-field error) rather than ondepartment.Done when
tests/test_departments.pyedits a contact that has a department, posts it tojobs:contact_updatewith another company and with no company, with the structure feature on and off, and gets a redirect, with the contact at the new company and in the right department (or none).