Merge lp:~jtv/maas/bug-1374388 into lp:~maas-committers/maas/trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Jeroen T. Vermeulen | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 3117 | ||||
Proposed branch: | lp:~jtv/maas/bug-1374388 | ||||
Merge into: | lp:~maas-committers/maas/trunk | ||||
Diff against target: |
82 lines (+39/-0) 3 files modified
src/maasserver/forms.py (+19/-0) src/maasserver/templates/maasserver/node_edit.html (+1/-0) src/maasserver/tests/test_forms_node.py (+19/-0) |
||||
To merge this branch: | bzr merge lp:~jtv/maas/bug-1374388 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jeroen T. Vermeulen (community) | Approve | ||
Raphaël Badin (community) | Approve | ||
Review via email: mp+236291@code.launchpad.net |
Commit message
Work around an “impedance mismatch” between Django's BooleanField in forms, and our use of forms for both UI and API.
The Node.disable_ipv4 checkbox could be enabled in the UI, but never disabled. In the API it could go both ways. The reason is that Django never submits a False value for an unchecked checkbox; it just doesn't include the value in the form submission. Our forms are rigged to interpret missing fields as ones that should stay unchanged. As a result, once disable_ipv4 was set to True, the UI simply ignored attempts to set it back to False.
The workaround adds an invisible input field to tell a UI-originated form submission from an API-originated one. A UI form shows all fields, so a missing boolean field means “set to False.” An API form must deal with callers omitting fields that were left out in order to keep them unchanged, so a missing boolean field does what it does now. This is particularly important with fields that are added in later versions.
Description of the change
The solution is one we can re-use in NodeGroup.
Jeroen
Nice! Although I understand the immediate goal is this fix the bug linked to this branch, I'm thinking about how we could generalize this so that similar problems can be fixed with minimal changes to the code (and ideally no change to the templates).